If you're working on a project that just uses Webp...
# javascript
d
If you're working on a project that just uses Webpack anyway, is there any benefit you get from using per-module granularity vs. whole-module granularity?
I have a small-ish project but I did some local tests, and it seems like... 1. whole-module granularity compiles on par or slightly faster 2. whole-module granularity results in a smaller final JS file (maybe the Kotlin compiler is smarter about DCE than Webpack is?)
Either way, I end up with a monolothic JS file at the end of the process
t
whole-program
is very useful in case of worker - you won’t have no 2 (or more) different sets of dependencies
And
whole-program
bundle is more optimal (because of mangling?!)
d
So
whole-program
actually has advantages over
per-module
? Even though
per-module
was made the default recently?
t
Yes
d
OK thanks 🙂
I was hoping that
per-module
would cut compile time down significantly but I wasn't seeing that. Not sure what a larger project looks like.
t
Only file-file compilation can be more effective: 1. Faster dev-server 2. Less bundle size in case of SPA (multiple entry points) 3. …
d
Is that a valid granularity option? Or are you talking theoretical?
t
For now it’s feature request only
d
Got it. Thank you for the detailed answer!
t
per-module
looks like intermediate step to “file-to-file” compilation. I hope 🙂
🤞 1
🤞🏾 1
c
My dream is ES6 support + file-to-file to support Vite fully 🫢
Currently with per-module, Vite is already a much smoother experience than Webpack in my experience (faster, and uses a lot less memory)
Vite's bundler (Rollup) makes ~20% smaller apps than Webpack (sample size of 1 though, so do your own test), which is comparable to Webpack + Google Closure Compiler (but the Closure compiler is extremely slow…)
c
are you using kotlin with vite? is that already possible?
c
Depends what you call possible. I'm feeding the output of the
per-module
Kotlin compiler into Vite. It's far from unleashing Vite's full power, since it can't do its per-file magic, but it's already a better dev experience IMO than using Webpack—the benefits of using Rollup for prod are great
If someone has the knowledge of how to transform that into a Gradle plugin, here's the setup: https://gitlab.com/opensavvy/decouple/-/blob/main/demo/web/build.gradle.kts#L25