5

I'm trying to compile some JS libraries that we have with lein-cljsbuild to integrate them in our ClojureScript code base. First I added some goog.provide in top of each file, and the files are hierarchically organised in a directory tree according to their namespace (like in Java). That is namespace a.b.c is in src-js/libs/a/b/c.js

I have put the JS files in the root directory of the projects in src-js/libs, and I have the following :compiler options for lein-cljsbuild:

{:id "prod",
 :source-paths ["src-cljs" "src-js"]
 :compiler
 {:pretty-print false,
  :libs ["libs/"]
  :output-to "resources/public/js/compiled-app.js",
  :optimizations :simple}}

None of the JS files get compiled into the compiled-app file. What's wrong?

I also tried to put them in resources/closure-js/libs without success.

I'm using lein-cljsbuild 0.3.0.

1 Answer 1

4

First, unlike what is suggested in some texts, you do not need to include your private closure library locations in any classpath configuration statement in your project.clj. So unless the "src/js" directory included in your "source-paths:" statement is for some other purpose, you can remove it.

Second, the only thing to add to your project.clj, for the sake of bringing in your private closure code, is the "libs:" reference you have made; BUT unlike what you have entered, that reference must be to a specific *.js file (or files) and not merely a directory. So if the library you want to used is in a file named test.js and that resides in the /src/js directory, your libs: entry would be: "src/js/test.js". See the cljs-build release notes if you want to use that plugin's default :libs directory option.

Third, (and it looks like you know this already, but this is what tripped me up) if you are using a browser-backed REPL (repl-listen option of cljsbuild), you still will not be able to load/reference/use your private library assets from that REPL until you include a :require statement somewhere in the source for your compiled-app.js (e.g. "(ns testing (:require [myprivatelib]))" ), THEN you must re-compile (lein cljsbuild once) and reload your browser page with a link to compiled-app.js. This brings in that code base. Otherwise, your browser REPL will just keep insisting that the namespace provided in your closure library is not defined.

I hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

src-js (minus, not slash!) is not in the classpath so I add to do that. You don't need to specify a particular library, you can specify a directory, it works but I had a bug: it doesn't recompile automatically the file in the hierarchy. See the bug tracker of cljsbuild. Finally my files were not compiled because a) they weren't required in a cljs file. b) there was a bug with file containing minus/hyphen symbols. See the bug tracker also.
Ok indeed it IS possible to specify a whole directory to compile JS files. As you mentionned the directory must be specified with the :lib keyword and NOT in the :source-path. In my example :libs should be "src-js/libs" and then it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.