简体   繁体   English

项目组织和cljsbuild配置需要名称空间

[英]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.

相关问题 Grunt + require.js配置一个简单的网站 - Grunt + require.js config for a simple website 现有文件中的模糊组织:{.... }。 必须指定 --org 命令行参数才能重新创建项目 - Ambiguous organization in existing files:{ .... }. The --org command line argument must be specified to recreate project 如何在qooxdoo中的项目中设置自定义共享名称空间并使用? - How to set up a custom shared namespace and use in my project in qooxdoo? 如果我只是编写clojurescript实用程序功能,是否需要cljsbuild插件? - Do I need cljsbuild plugin if I am just writing clojurescript utility functions? TeamCity:找不到类型或命名空间,但引用存在且我的项目在本地编译 - TeamCity: Type or namespace cannot be found, but the reference exists and my project compiles locally 使用Web.config阻止ASP.NET网站项目构建某些目录? - Prevent ASP.NET Website project from building certain directories by using Web.config? ASP.NET MVC:是否有语法可访问web.config中的项目条件编译符号 - ASP.NET MVC: Is there a syntax to access a project conditional compile symbol in web.config 未定义对`(匿名名称空间)的引用:: - Undefined reference to `(anonymous namespace):: 摆脱`My`命名空间 - Getting rid of the `My` namespace F#:未定义名称空间 - F#: the namespace is not defined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM