Closed marcin-wosinek closed 3 years ago
Sorry but no. This will actually break things because of https://underscorejs.org/docs/modules/index-default.html (note "Add all of the Underscore functions to the wrapper object"). In other words, the fully composed Underscore cannot be tree-shaken because all functions are mixed into _
.
You can have perfect "treeshaking" by composing your own Underscore. I extensively documented how to do that in https://juliangonggrijp.com/article/introducing-modular-underscore.html (which is also linked from the Underscore website). If you prefer a video introduction, refer to https://www.telerik.com/react-wednesdays/what-i-learned-modularizing-underscore-with-julian-gonggrijp or https://www.youtube.com/watch?v=d4ORLdr3vWE.
Thanks for all the work done on this project.
I've been trying to use tree-shacking with the module. Looks that the current convention among bundler is to assume all code has side effects (cannot be removed, even if not used directly), unless there is
sideEffect: false
set onpackage.json
(https://github.com/evanw/esbuild/issues/50#issuecomment-634107700)The solution I'm proposing here can be see in action here:
...
asset main.js 19.7 KiB [emitted] [minimized] (name: main) orphan modules 83.1 KiB [orphan] 161 modules runtime modules 670 bytes 3 modules ./src/index.js + 161 modules 83.2 KiB [built] [code generated] webpack 5.50.0 compiled successfully in 1252 ms