Project organization and cljsbuild config to require namespace

二次信任 提交于 2019-12-13 06:06:30

问题


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

I'd like file1.cljs(namespaced as file1.file1) and file2.cljs(namespaced as file2.file2) to require required.cljs(namespaced as required.required).

My :cljsbuild looks like:

: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:

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


回答1:


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"}}]}

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.

You can find an example of this simple layout in the simple example project from lein-cljsbuild

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.



来源:https://stackoverflow.com/questions/31879581/project-organization-and-cljsbuild-config-to-require-namespace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!