Find a way to automatically test against Webpack's tree-shaking
lukastaegert opened this issue · 1 comments
Currently, eslint-plugin-tree-shaking features a test suite of > 350 code snippets which are also automatically run against rollup. These tests check that if code is not tree-shaken, then there needs to be an ESLint error. That is, you can be fairly certain that if there are no ESLint errors, you do not have any hidden side-effects in rollup. Unfortunately, the same cannot be said for Webpack. This is particularly bad since Webpack is the final bundler for most Webapps and those would benefit most from tree-shaking.
What I am looking for is a way to run a code snippet through Webpack and reliably determine if tree-shaking would remove this snippet. Main problems:
- Webpack always adds a lot of boilerplate code which is always present
- Tree-shaking is realized via comments. In order for the code to be actually removed, Uglify needs to be run
- After minification, it is even more difficult to determine which code is boilerplate and which is not
If anyone has some good ideas here, this would be greatly appreciated.
What about running webpack+uglify twice for a given code snippet, once with tree-shaking enabled, once without, and diffing the two outputs? If they're the same, tree shaking has failed, and that can be used to either pass or fail the test.