3 ms·
These look really solid! For anyone else who was confused by the minimal explanation of the "sideEffects: false" feature, apparently this targets cases where (
by fenomas 9y ago
These look really solid!
For anyone else who was confused by the minimal explanation of the "sideEffects: false" feature, apparently this targets cases where (1) module A exports some code, (2) module B imports from A and exports end points, some of which depend on A, and (3) module C imports code from B that doesn't reference code from A.
In this situation by default webpack assumes that the code from A might have side effects inside B, but if A declares "sideEffects: false" in its package.json, the tree-shaker will assume it's safe to omit module A from the final bundle.
Incidentally the end user can also declare in their config that module B should use sideEffects:false, even if the module doesn't declare it. Details here: https://github.com/webpack/webpack/issues/6065 https://github.com/webpack/webpack/issues/6065
- wereHamster 9y agoToo many assumptions, too many ways how developers can make mistakes, by declaring code side-effect free while it has some.
- WorldMaker 9y agoSure, but if you author a package and put sideEffects: false in your package.json, but don't actually follow through on that in your code, that's a bug in your library, and the easiest fix is a quick PR to remove sideEffects: false from package.json, with a stop gap that if I find a library with that sort of bug I could tell webpack sideEffects: true to override the behavior until the bug is fixed.