Tree-Snaking
effect
- Js context eliminating unused code
principle
- Use ES6 Moudles static resolution, dependencies determine in advance
- Import removing unused code
achieve
- By using their own webpack dependencies between ES6 Moudles analysis module is removed without the use of import module references in code.
- Provided webpack mode = production, using a plug (terser-webpack-plugin) code unused for deletion.
note
- webpack must be es6 modules
Use as a module without side effects (side Effect) of
No side effects means: given the same input, there is the same output, without changing the external environment
Set sideEffect in package.json, set the side effects of file
//package.json
{
name: 'webpack-project',
sideEffect: ["./index.js"],
}