Skip to content

Commit 2f19976

Browse files
committed
add some more advanced usage notes
1 parent 9ad350d commit 2f19976

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/content/guides/tree-shaking.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ related:
1414
url: https://medium.com/webpack/webpack-4-beta-try-it-today-6b1d27d7d7e2#9a67
1515
- title: Debugging Optimization Bailouts
1616
url: https://webpack.js.org/plugins/module-concatenation-plugin/#debugging-optimization-bailouts
17+
- title: Issue 6074 - Add support for more complex selectors for sideEffects
18+
url: https://github.com/webpack/webpack/issues/6074
1719
---
1820

1921
_Tree shaking_ is a term commonly used in the JavaScript context for dead-code elimination. It relies on the [static structure](http://exploringjs.com/es6/ch_modules.html#static-module-structure) of ES2015 module syntax, i.e. [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [`export`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export). The name and concept have been popularized by the ES2015 module bundler [rollup](https://github.com/rollup/rollup).
@@ -130,6 +132,8 @@ If your code did have some side effects though, an array can be provided instead
130132
}
131133
```
132134
135+
The array accepts relative, absolute, and glob patterns to the relevant files. It uses [micromatch](https://github.com/micromatch/micromatch#matching-features) under the hood.
136+
133137
T> Note that any imported file is subject to tree shaking. This means if you use something like `css-loader` in your project and import a CSS file, it needs to be added to the side effect list so it will not be unintentionally dropped in production mode:
134138
135139
```json
@@ -142,6 +146,8 @@ T> Note that any imported file is subject to tree shaking. This means if you use
142146
}
143147
```
144148
149+
Finally, `"sideEffects"` can also be set from the [`module.rules` config option](https://github.com/webpack/webpack/issues/6065#issuecomment-351060570).
150+
145151
## Minify the Output
146152
147153
So we've cued up our "dead code" to be dropped by using the `import` and `export` syntax, but we still need to drop it from the bundle. To do that, we'll use the `-p` (production) webpack compilation flag to enable the uglifyjs minification plugin.

0 commit comments

Comments
 (0)