FYI, I made a quick test on the generated js file size for the following code.
import times
echo now()
Run
I compiled the code in debug, release, release+danger mode. Also, I used google
closure compiler (gcc) in simple mode for minification. And also, I wrap the
danger code with a function, this allow gcc to rename top level variables and
remove unused local variables. Here the result
209746 byte test.debug.js
169579 byte test.debug.min.js
57103 byte test.release.js
46520 byte test.danger.wrap.js
46502 byte test.danger.js
31989 byte test.release.min.js
25159 byte test.danger.min.js
17661 byte test.danger.wrap.min.js
Run
Run with the following bash.
nim js test.nim && mv test.js test.debug.js
nim js -d:release test.nim && mv test.js test.release.js
nim js -d:release -d:danger test.nim && mv test.js test.danger.js
java -jar closure-compiler-v20201207.jar test.debug.js > test.debug.min.js
java -jar closure-compiler-v20201207.jar test.release.js >
test.release.min.js
java -jar closure-compiler-v20201207.jar test.danger.js > test.danger.min.js
# wrap inside a function
echo '(function(){' > test.danger.wrap.js
cat test.danger.js >> test.danger.wrap.js
echo '})()' >> test.danger.wrap.js
java -jar closure-compiler-v20201207.jar test.danger.wrap.js >
test.danger.wrap.min.js
Run
Nim js has an advantage that compile into one giant js file with many top level
functions, if wrapping this into a function scope, gcc in simple mode should be
good at minify this pattern. Unlike other packer which usually wrap each file
into a function and use some way to simulate import/export, which gcc in simple
mode cannot minify it.