Examples of what I tried and results written up here, but tl;dr it hasn’t worked out so far
It’d be good to hear if anyone has achieved this with some other npm lib and what compiler setup you have?
Thanks, but in this case I do know what the code looks like and so does Google Closure via :module-type :es6
The very short answer is that dead code elimination doesn’t work with code that isn’t written for it.
So several things that the “pretend to be ESM” js-joda file does are not compatible with DCE. Basically avoid all “dist” bundled files since in that process much of the actual ESM code is lost.
FWIW I did try a foreign-lib pointed to the js-joda src dir, but doing that I get compiler errors like ’ This language feature is only supported for ECMASCRIPT6 mode or better’ . I looked about for some flags to set or something that might fix this but didn’t find anything.
The long answer is unfortunately a year long or so. Don’t really have any pointers to give. I wrote about a bunch of stuff on my blog but thats mostly about shadow-cljs and why it does the stuff it does.
Overall I have no clue anymore what CLJS does with
I did however port your example to
shadow-cljs since I know exactly what that does.
To compare you can look at the build-reports
In short these are 3 separate builds. One using your minimal no-deps entry and 2 using js-joda. One variant just includes the “regular” npm package (similar to what you’d get from cljsjs) and one actually trying to run everything through
:advanced compilation. As you can see it does make a difference but not as much as you’d probably expect.
Note that I didn’t actually try running the compiled code at all. So no clue if it even survived the
:advanced compilation (most packages nowadays don’t).
Overall the Closure Compiler is fully capable of running strict ESM code through
:advanced compilation with full DCE. However the
js-joda.dist.esm.js is not strict ESM code. It is some kind of processed “mess” that basically just has
export added at the end to “pretend to be ESM”. All “modern” language features (eg.
class) were rewritten by babel. Those produce problems for the Closure Compiler and hinder DCE.
much appreciated… I’ll get reading
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.