[英]Project organization and cljsbuild config to require namespace
How do I organize my project structure and configure cljsbuild to require my own namespace? 如何组织项目结构并配置cljsbuild以要求我自己的名称空间? For example in my
project/src-cljs
folder I have: 例如在我的
project/src-cljs
文件夹中,我有:
└── project
├── file1
│ └── file1.cljs
├── file2
│ └── file2.cljs
└─── required
└── required.cljs
I'd like file1.cljs
(namespaced as file1.file1
) and file2.cljs
(namespaced as file2.file2
) to require required.cljs
(namespaced as required.required
). 我想
file1.cljs
(的命名空间file1.file1
)和file2.cljs
(的命名空间file2.file2
)要求required.cljs
(的命名空间required.required
)。
My :cljsbuild
looks like: 我的
:cljsbuild
看起来像:
:cljsbuild {:builds
[{:source-paths ["src-cljs/project/file1"]
:compiler {:output-to "resources/public/js/file1.js"}}
{:source-paths ["src-cljs/project/file2"]
:compiler {:output-to "resources/public/js/file2.js"}}]}
When I (:require [required.required :as required])
and compile I get the exception: 当我
(:require [required.required :as required])
并编译时,出现异常:
Caused by: clojure.lang.ExceptionInfo: No such namespace: required.required, could not locate required/required.cljs, required/required.cljc, or Closure namespace "required.required" at line 1 src-cljs/project/file1/file1.cljs
You don't usually want a separate js output file and cljsbuild profile for each namespace. 您通常不需要每个名称空间的单独的js输出文件和cljsbuild配置文件。 You want one single cljsbuild profile including all of your namespaces.
您想要一个包含所有名称空间的单个cljsbuild配置文件。 Something like:
就像是:
:cljsbuild {:builds
[{:source-paths ["src-cljs/project"]
:compiler {:output-to "resources/public/js/project.js"}}]}
Not only that: you might want to have ["src-cljs"] as :source-paths
and then name your namespaces like project.ns1.sub-ns1
. 不仅如此:您可能希望将[“ src-cljs”]作为
:source-paths
,然后将名称空间命名为project.ns1.sub-ns1
。 But you can do it without the project
ns prefix just fine. 但是您可以在没有
project
ns前缀的情况下做到这一点。
You can find an example of this simple layout in the simple example project from lein-cljsbuild 您可以在lein-cljsbuild的简单示例项目中找到这种简单布局的示例。
Looking to the cljsbuild README, it seems like you were taking the path of "Multiple build configurations" . 期待cljsbuild自述文件,似乎您正在采用“多重构建配置”的路径。 In practice this is mostly used to have separate build profiles for your main code and the tests working against that code.
实际上,这通常用于为您的主要代码和针对该代码的测试提供单独的构建配置文件。 That's shown in the advanced example .
这在高级示例中已显示 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.