5

I want to use some plain .js files in my ClojureScript project. I'm building it using lein-cljsbuild and the .js files are standard Google Closure namespaces with proper goog.provide declarations. So basically what I want is to merge them into the compilation sources that goes int the Closure Compiler. Is that possible?

tillda
  • 18,150
  • 16
  • 51
  • 70
  • what you are after is an extern. https://code.google.com/p/closure-compiler/wiki/FAQ#How_do_I_write_an_externs_file? – lennel Jun 21 '13 at 10:30
  • 1
    @lennel I'm pretty sure that it isn't an extern. They are asking how to pass an additional js source file to closure-compiler along with their clojure generated sources. – Chad Killingsworth Jun 21 '13 at 12:51
  • I haven't worked with clojure script but according to this: http://stackoverflow.com/questions/9723111/what-are-the-namespace-gotchas-for-clojurescript-when-coming-from-clojure/9724746#9724746 you can use any closure compiler compatible code wtih: (:use [myapp.myns :as myns]) Not sure if you have to run calcdeps.py to generate the deps.js http://stackoverflow.com/questions/16432800/wiki-how-to-use-lime-how-to-use-closure-compiler-with-3rd-party-closure-libr (didn't put this in an answer because I'm not sure it's the answer). – HMR Jun 22 '13 at 00:28
  • @HMR you will have to calculate deps.@Chad, i was thinking 2 step compilation, but rereading the question tells me I was off. – lennel Jun 22 '13 at 10:35
  • AFAIK this is just about getting the .js files into the compiler.jar command, right? – tillda Jun 22 '13 at 12:10
  • @tillda Yes, I would think so. ` (:use [myapp.myns :as myns])` would probably translate to `goog.require("myapp.myns")` for the compiler.jar to find myapp.myns it has to have an entry in deps.js but you can have calcdeps.py add those for you. – HMR Jun 24 '13 at 04:08
  • Take a look here: http://lukevanderhart.com/2011/09/30/using-javascript-and-clojurescript.html – Rodrigo Taboada Jul 04 '13 at 18:05
  • Hm, actually rtaboada already linked to a post with the correct answer. @rtaboada: Would you like to post an answer here? – Michał Marczyk Jul 09 '13 at 21:21

1 Answers1

2

You should be able to add your Closure-aware JS files to :libs under the :compiler key in your build specification:

;; in project.clj
:cljsbuild {:builds [{:source-paths [...]
                      :compiler {:libs ["foo.js"]    ; <- add the libs here
                                 ...}}]}
Michał Marczyk
  • 83,634
  • 13
  • 201
  • 212
  • Thanks! Some notes for future readers: https://groups.google.com/forum/#!topic/clojurescript/Xi515LCv6kU – tillda Jul 11 '13 at 15:04