我的project.clj
有,
:cljsbuild {:builds
{:app
{:source-paths ["src/cljs" "src/cljc"]
:compiler {:output-to "target/cljsbuild/public/js/app.js"
:output-dir "target/cljsbuild/public/js/out"
:main "my.core"
:asset-path "/js/out"
:optimizations :none
:source-map true
:pretty-print true}}}}
并且我使用app.js
将list.html
包括在我的Selmer中,
{% block page-scripts %}
{% script "/js/app.js" %}
{% endblock %}
list.cljs
的结尾,我有
(r/render [list] (.getElementById js/document "content"))
到目前为止一切顺利。
现在,我想再创建一个页面,例如detail.cljs
,我也想进行类似的渲染,
(r/render [detail] (.getElementById js/document "content"))
问题是,我只有一个app.js
,并且在detail.html
中包含它也会在此呈现列表内容。顺便说一句,我想要一个list
页面的网址,另一个是detail
的网址。
问题:
我应该怎么做?
过去两年来,使用Deps / CLI工具以及Figwheel Main(又名Figwheel 2.0),比旧的Leiningen方法要容易得多。只需查看Create a Build的页面figwheel.org
,然后创建多个*.cljs.edn
文件,例如:
some-page.cljs.edn
another-page.cljs.edn
...
每个都可以很简单:
{:main some-page.core}
并通过以下方式进行编译:
clojure -m figwheel.main --build-once some-page
将产生输出文件
target/public/cljs-out/some-page-main.js
请务必查看Figwheel的Code Splitting文档,以及Code Splitting上的clojurescript.org
。当然,确定从头开始遍历所有Tutorial和Documentation。享受!
对于shadow-cljs
,有Code Splitting ClojureScript个示例应用程序和一个blog entry。
注意:您也可以查看Extra Mains功能,但这受到更多限制。
使用shadow-cljs,您可以在构建规范中指定具有不同init-fn
的多个模块。
您的shadow-cljs.edn
可能包含以下内容:
{:builds {:client {:target "browser"
:modules {:some-page {:init-fn org.example.foo/run}
:another-page {:init-fn org.example.bar/run
:depends-on #{:some-page}}}}}}
.js
文件的名称由模块名称确定,此处为some-page.js
和another-page.js
。