This is a super-low-priority request: could the Elm compiler emit the
following line at the end of its JS output:
window['Elm'] = Elm;
I’m used to using Google Closure Compiler after Clojure so I tried it with
my tiny ~400 LOC Elm app, and without this line above, the `Elm` object
gets renamed and unavailable in the browser. The line functions as an
“export” Closure Compiler lingo [1].
With this in place, if I run
$ elm-make Main.elm --output=main.js
$ yarn add google-closure-compiler-js -dev
$ yarn run google-closure-compiler-js --compilationLevel ADVANCED main.js
and pipe the result to a minified file, the original Elm-produced JS goes
from 268 KB to an 80 KB file and my app works flawlessly. (Another data
point: uglify-js produces a 164 KB minified file.)
--
A couple of further notes, if anyone else is interested in adding Google
Closure Compiler to their workflow.
It takes 30~ seconds to run advanced compilation on my little app, so I
have two HTML files: (1) an ephemeral dev.html that loads the original
Elm-emitted JS and (2) a real index.html that loads the compiled version.
During development, I just look at dev.html to see my changes quickly.
Besides the compilation time, another reason not to use the compiled code
during development is that record field names get minified. E.g., I have a
quick `text (toString model)` and:
- original: `{ err = "", token = "eyJ...", target = Just { target = "冫",
pos = 1` ...
- compiled: `{ ba = "", S = "eyJ...", target = { a = "Just", b = { target =
"冫"` ...
I have a little build script that tacks on the export to the Elm-emitted
JS, makes the dev.html out of index.html, and kicks off the Closure
Compiler. It sounds heavy but the script is really short: see [2].
[1] https://developers.google.com/closure/compiler/docs/api-tutorial3#export
[2] https://github.com/fasiha/kanji-abecedario/blob/gh-pages/build.sh and
the `min` task is of course in `package.json` but it’s not bad either.
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.