Skip to content

Update tree-shaking.md #4164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/content/guides/tree-shaking.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ The [`sideEffects`](/configuration/optimization/#optimizationsideeffects) and [`

__`sideEffects` is much more effective__ since it allows to skip whole modules/files and the complete subtree.

`usedExports` relies on [terser](https://github.com/terser-js/terser) to detect side effects in statements. It is a difficult task in JavaScript and not as effective as straighforward `sideEffects` flag. It also can't skip subtree/dependencies since the spec says that side effects need to be evaluated. While exporting function works fine, React's Higher Order Components (HOC) are problematic in this regard.
`usedExports` relies on [terser](https://github.com/terser-js/terser) to detect side effects in statements. It is a difficult task in JavaScript and not as effective as straightforward `sideEffects` flag. It also can't skip subtree/dependencies since the spec says that side effects need to be evaluated. While exporting function works fine, React's Higher Order Components (HOC) are problematic in this regard.

Let's make an example:

Expand Down Expand Up @@ -241,7 +241,9 @@ Terser actually tries to figure it out, but it doesn't know for sure in many cas

But we can help terser by using the `/*#__PURE__*/` annotation. It flags a statement as side effect free. So a simple change would make it possible to tree-shake the code:

`var Button$1 = /*#__PURE__*/ withAppProvider()(Button);`
```javascript
var Button$1 = /*#__PURE__*/ withAppProvider()(Button);
```

This would allow to remove this piece of code. But there are still questions with the imports which need to be included/evaluated because they could contain side effects.

Expand Down