Given the instructions on minification in the official docs, I put together a small NPM module for just that.
The idea is to have a nicely packaged solution that can be optimized and maintained separately, instead of having people maintain their own scripts with instructions to, for example, Uglify.js.
I built this for myself, but I hope it’s something you will want to use, contribute to, etc.
I am not a very experienced developer, so guidance and instructions of any kind from more senior community-members would be much appreciated!
Let me know what you think!
This is definitely a good idea, better to have one tool that gives you the optimal uglifyjs set up out of the box than having to configure it yourself for every project.
However I think there’s an easily made oversight in the current implementation; it only does one uglifyjs pass which has both
mangle enabled (https://github.com/opvasger/elm-minify/blob/1c8ae8fe3a1f02ac19d0abe8f62cafd5c7d4f4b5/src/cli.js#L23).
It says in the elm docs that you have to do compress and then mangle in separate calls to uglfyjs for the
pure_funcs optimisation to take effect:
uglifyjs is called twice there. First to
--compress and second to
--mangle . This is necessary! Otherwise
uglifyjs will ignore our
But once this issue is resolved I think this would a very useful tool!
Thank you! I’d appreciate issues submitted directly on Github, so I can follow up there
I tried reconfiguring the implementation to “mangle” in a separate call, but got the same output. I’m not sure if this is related to the version of Uglify.js I’m using or something else.
I definitely want to have this optimized to run fast and produce the smallest possible output while maintaining Elms runtime guarantees, so I’ll investigate further on Github!
npm install -g elm-minify, I
cd'd to a directory with an
elm.js output of
elm make and did
elm-minify elm.js. It created a new file,
elm.min.js, about half the size of the original, with a single line of minified JS, but no compression that I could see. The new file works. But I got the error below. Missing dependency?
$ elm-minify elm.js
TypeError: console.table is not a function
at Object.<anonymous> (/usr/local/lib/node_modules/elm-minify/src/cli.js:37:9)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
Thank you for feedback! I’ve polyfilled it in as of v1.0.2, which was just published!
I would really appreciate all future issues to be reported directly on github
My bad. Will do, though there probably won’t be a next time, since it now works:
$ elm-minify elm.js
(index) │ SIZE (KB) │
INPUT (elm.js) │ 297.158 │
OUTPUT (elm.min.js) │ 158.172 │
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.