The fourth iteration of meteor 2.0 beta is available and is bringing Tree Shaking with it.
What is it?
Tree-shaking is a technique that the bundler uses to remove unused files and code from the final bundle. This PR implements 2 strategies:
- Remove unused Files, by checking es6 imports/exports
- Remove unused Exports, by checking imports/exports.
This version still doesn’t implement verification for actual usage in the code. It is restricted to imports, and also deals with dynamic and nested imports.
How to use it?
First, update your meteor version to:
meteor update --release METEOR@2.0-beta.4
Tree shaking comes disabled by default, as Meteor used to rely a lot on global variables, so it’s safer to enable it on demand.
Using inside your app
For enabling tree shaking in your app, simply add the flag:
to your package.json.
Using it inside packages
For packages, you can use on package.js the following:
inside the Package.onUse section.
If your package uses api.export(), it will be automatically marked as side-effects true.
Please help us test this, as we can face several non-tested flows, as the static analysis is hard to cover on tests. Don’t forget to leave your feedback on 2.0 PR here: https://github.com/meteor/meteor/pull/11206 or inside Tree-shaking PR itself: https://github.com/meteor/meteor/pull/11164