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:
sideEffects: false
to your package.json.
Using it inside packages
For packages, you can use on package.js the following:
api.setSideEffects(false);
inside the Package.onUse section.
If your package uses api.export(), it will be automatically marked as side-effects true.
That’s quite a surprise @a4xrbj1… Are you using lodash or anything alike? Make sure you are using lodash-es packages so it can be tree shaked. Commonjs modules are never shaked, so it can be getting into this case. Also, always compare it with it’s minified versions.
@stolinski as @rjdavid said the best way would be to run bundle visualizer before and after (you can disable the flag on package.json to do the test), always running it with --production
I just gave Meteor 2.0-beta.4 a shot, no noticeable problems either in development or deployed to ubuntu (yay!), however my bundle size before and after is the same built for either mac or linux.
I have our dev team all using beta4, and we are seeing high memory usage (~2.4G) this happens quite quickly (ie it’s probably not a memory leak over time). Performance isn’t good, but that may be related to the high memory usage
Some more information - I backtracked to a version of our app from 1 Nov, and did a fresh checkout/build, and memory usage/performance is ok. That was using Meteor 2.0-beta.2. I upgraded it to Meteor 2.0-beta.4 and the problem came back. It could be Meteor 2.0-beta.4, or one of the new packages causing the prob.