项目组织和cljsbuild配置要求命名空间 [英] Project organization and cljsbuild config to require namespace
问题描述
如何组织我的项目结构并配置cljsbuild以需要我自己的命名空间?例如在我的 project / src-cljs
文件夹中我有:
How do I organize my project structure and configure cljsbuild to require my own namespace? For example in my project/src-cljs
folder I have:
└── project
├── file1
│ └── file1.cljs
├── file2
│ └── file2.cljs
└─── required
└── required.cljs
我想要 file1.cljs
(命名空间为 file1.file1
)和 file2.cljs
file2.file2
)要求 required.cljs
(命名空间为 required.required
)。
I'd like file1.cljs
(namespaced as file1.file1
) and file2.cljs
(namespaced as file2.file2
) to require required.cljs
(namespaced as required.required
).
我的: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"}}]}
当I [required.required:as required])
并编译我得到异常:
When I (:require [required.required :as required])
and compile I get the exception:
原因:clojure.lang .ExceptionInfo:没有这样的命名空间:required.required,在第1行找不到required / required.cljs,required / required.cljc或Closure命名空间required.requiredsrc-cljs / project / file1 / file1.cljs
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
推荐答案
通常不需要为每个命名空间使用单独的js输出文件和cljsbuild配置文件。你想要一个单一的cljsbuild配置文件包括所有的命名空间。像:
You don't usually want a separate js output file and cljsbuild profile for each namespace. You want one single cljsbuild profile including all of your namespaces. Something like:
:cljsbuild {:builds
[{:source-paths ["src-cljs/project"]
:compiler {:output-to "resources/public/js/project.js"}}]}
b $ b
不仅如此:您可能希望将[src-cljs]设置为:source-paths
,然后命名您的命名空间,例如 project.ns1.sub-ns1
。但是你可以不用项目
ns前缀就好。
Not only that: you might want to have ["src-cljs"] as :source-paths
and then name your namespaces like project.ns1.sub-ns1
. But you can do it without the project
ns prefix just fine.
你可以找到这个简单布局的例子在来自lein-cljsbuild的简单示例项目中
You can find an example of this simple layout in the simple example project from lein-cljsbuild
查看cljsbuild README,看起来你正在走多个构建配置。在实践中,这通常用于具有单独的构建配置文件为您的主要代码和测试工作反对该代码。显示在高级示例。
Looking to the cljsbuild README, it seems like you were taking the path of "Multiple build configurations". 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.
这篇关于项目组织和cljsbuild配置要求命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!