Search code examples
buildclojureclojurescriptleiningen

How to setup Leiningen/ClojureScript compiler to support user scripts?


User scripts require to start with a metadata block. How one can setup Leiningen and/or ClojureScript compiler to insert predefined metablock from e.g. a text file?

I have tried following:

; test
;; test 2
(comment test 3)

but it got stripped (probably because {:optimizations :advanced}?).

Please try to explain and describe your answers well, I am a total noob in Clojure and know almost nothing about Leiningen (I managed to get a simple ClojureScript build functional, but that's about it - I wanted to start learning Clojure by writing simple user scripts which I may actually use).


Solution

  • You can use the :preamble option to prepend the output files with a block of data. You can see the compiler option here (scroll down just a bit... the link to the preamble section doesn't work because there's another div that has the preamble id).

    For reference, here's the documentation:

    :preamble

    Prepends the contents of the given files to each output file. Only valid with optimizations other than :none.

    Defaults to the empty vector []

    :preamble ["license.js"]