Skip to content

Add note about --optimize-minimize is not required for tree shaking #1474

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 2 commits into from
Aug 3, 2017

Conversation

esbenp
Copy link
Contributor

@esbenp esbenp commented Aug 1, 2017

Idea for #1473 (also see #1331). Opener for discussion - feedback welcome.

Copy link
Collaborator

@skipjack skipjack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good start and will be a decent quick fix for the issue as you mentioned. We can then go into detail when we hit this guide for real in #1258 and in the process of resolving #1331. See my note about elaborating but aside from that I think we can get this merged soon.

@@ -84,3 +84,5 @@ function(e,t,n){"use strict";function r(e){return e*e*e}t.a=r}
/* ... */
function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(0);console.log(n.i(r.a)(5))}
```

T> Note, using the `--optimize-minimize` flag is NOT required for tree shaking to occur. Tree shaking will occur when using a production configuration. This can also be configured directly in a `webpack.config.js` file. Read [production build](/guides/production) for an in-depth guide on how to create a production config file.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of saying:

Tree shaking will occur when using a production configuration.

I think we should be more specific on exactly what's necessary which I think, as I mentioned in #1473, is allowing webpack to actually resolve import / export statements (i.e. disabling any transpilers like babel from resolving them). And, including the UglifyJsPlugin. The import / export is already mentioned at the top of this guide so maybe just noting that either --optimize-minimize should be used (which includes the UglifyJsPlugin under the hood) or the plugin can be configured directly (likely in a "production" configuration).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I think that makes sense. However, I am unsure about the first part. Do you mean using something like babel-plugin-resolver when you say resolving using transpilers? I am not sure how transpilers work, but I am assuming loading your JS files with babel-loader does not resolve any imports, right?

What do you think about something along the lines of

Note, using the --optimize-minimize flag is NOT required for tree shaking to occur. Tree shaking will occur when Webpack resolves your import/export statements and when you are including the UglifyJsPlugin. You can either include the UglifyJsPlugin using the --optimize-minimize flag or by adding the plugin manually to your plugins key of your configuration file. Read production build for an in-depth guide on how to create a production config file.

Copy link
Collaborator

@skipjack skipjack Aug 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, I am unsure about the first part. Do you mean using something like babel-plugin-resolver when you say resolving using transpilers? I am not sure how transpilers work, but I am assuming loading your JS files with babel-loader does not resolve any imports, right?

Depends on how you have the babel and the babel-loader configured. With certain plugins, you'll need to set { modules: false } in order to let webpack resolve the import and export syntax.

What do you think about something along the lines of...

Definitely sounds better... I might reword/simplify as:

Note that the --optimize-minimize flag enables tree shaking by including the UglifyJsPlugin behind the scenes. Alternatively, the UglifyJsPlugin can be included manually in the plugins section of your configuration file. The plugin, combined with webpack's resolving of import and export statements, is what makes tree shaking possible. See the production build guide for more information.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a better wording, I agree. I have updated the diff to your suggestion.

@skipjack
Copy link
Collaborator

skipjack commented Aug 3, 2017

Great, thanks @esbenp! Re-running the build due to some timeouts (which we should really be ignoring -- will address this finally in a separate PR).

Once the build passes we should be able to get this merged -- at which point I'll close out #1473 but make a note in #1331 that this should be one of the things we address in the rewrite.

@skipjack skipjack merged commit 777e582 into webpack:master Aug 3, 2017
dear-lizhihua referenced this pull request in docschina/webpack.js.org Aug 5, 2017
Note that --optimize-minimize is not required for tree shaking.

Closes #1473
Ref #1331
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants