How to serve clojurescript over flask

532 views Asked by At

I have a small Flask app and I want to use some ClojureScript to enhance the user experience on the client-side.

Now I have trouble serving clojurescript via flask, as the paths get mixed up.

Flask asserts that static files like Javascript scripts lie in a directory static. I have changed my project.clj so that the compile target is put there:

                     :output-to  "static/plot.js"
                     :output-dir "static"

Unfortunately, when loading this file, it cannot load the dependent files with goog.require:

"ClojureScript could not load :main, did you forget to specify :asset-path?"

I believe that what is missing is a leading /static instead of static in the paths.

Can I specify a prefix with leiningen cljsbuild or clojurescript for those inlcudes?

1

There are 1 answers

0
Daniel Compton On BEST ANSWER

You need to specify an :asset-path in your compiled options (as the error message suggests). From https://github.com/clojure/clojurescript/wiki/Compiler-Options#asset-path

When using :main it is often necessary to control where the entry point script attempts to load scripts from due to the configuration of the web server. :asset-path is a relative URL path not a file system path.

   :asset-path "assets/js"