Observations
Measured based on build-artifacts from rtfeldman/elm-spa-example using Elm 0.19.1
Minifier |
Version |
Output |
Gzipped |
none |
N/A |
373.645kb |
66.471kb |
esbuild(without pure-flags) |
0.9.6 |
117.121kb |
36.619kb |
esbuild(with IIFE-flag) |
0.9.6 |
117.121kb |
36.616kb |
esbuild |
0.9.6 |
117.121kb |
36.611kb |
google-closure-compiler (with advanced-flag) |
20210302.0.0 |
Error |
N/A |
google-closure-compiler |
20210302.0.0 |
97.398kb |
31.157kb |
terser |
5.6.1 |
94.652kb |
29.824kb |
uglify-js |
3.13.3 |
92.621kb |
29.508kb |
Evan Wallace did comment on the known limitations of the optimization-pass:
It could still make sense to build an advanced optimization pass into esbuild at some point in the future, but I’d like to direct development efforts on getting more of esbuild’s end-to-end bundling story in place first. Code splitting, top-level await, CSS, and also maybe HTML are all more of a priority for me, especially since Terser is moving to native code.
Method
Gzipped using gzip -k build/*
Measured using wc -c build/*
# build Elm code
elm make --optimize src/Main.elm --output=build/elm.js
# Optimize with EsBuild. Add '--format=iife' or remove all '--pure:' flags to run it in the other modes.
esbuild --bundle --minify --pure:A2 --pure:A3 --pure:A4 --pure:A5 --pure:A6 --pure:A7 --pure:A8 --pure:A9 --pure:F2 --pure:F3 --pure:F3 --pure:F4 --pure:F5 --pure:F6 --pure:F7 --pure:F8 --pure:F9 --outfile=build/elm.esbuild.js build/elm.js
# Optimize with Uglify-js
uglifyjs build/elm.js --compress 'pure_funcs=[F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9],pure_getters,keep_fargs=false,unsafe_comps,unsafe' | uglifyjs --mangle --output build/elm.uglify.js
# Optimize with Terser. Config is pasted from Uglify-js
terser build/elm.js --compress 'pure_funcs=[F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9],pure_getters,keep_fargs=false,unsafe_comps,unsafe' | terser --mangle --output build/elm.terser.js
# Run Google-closure-compiler in simple mode, as advanced fails for some reason...
google-closure-compiler --js build/elm.js --js_output_file build/elm.google-closure-compiler.js