2
votes

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).

1
My guess here is, that this would have to be supported in cljs/closure. If that is just a "text block" on the beginning of the generated file, i'd just do a cat metadata compiled.js > metadata.js step after compilation. - cfrick
Yes, I don't think it supports it directly. I have no clue about Leiningen and whether it supports some kind of after compilation hooks (also since the build file is in Clojure, it's kinda hard for me, because I want this project to use for learning Clojure). I didn't want to go witch hacky solutions like a script in bash calling Leiningen and then manipulating resulting file - it feels wrong, IMO it should be handled by the build tool (at least that's the recommended way in other build tools I used so far). - monnef

1 Answers

3
votes

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