I have included a test repository to showcase code and config.
See test repo @ https://github.com/r0skar/polished-tree-shaking
yarn build./dist.Parcel should strip all unused modules from polished and be more or less the same size as the webpack bundle.
Parcel includes the whole polished bundle.
| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.11.0
| Node | 11.9.0
| Yarn | 1.13.0
| Operating System | Linux 4.20-7
You need to enable minification for tree shaking to work. Without --no-minify, I get 12.34 KB with your example.
You are right, the bundle size is drastically decreased when not using --no-minify, however if you look at the file, you will see that there is a lot of unused stuff still included. Also, the webpack version is about 7 times smaller at 1.8KB.
Is this maybe related to #2650? Not because of the environments but because of the dependencies that are loaded even if they are unused?
This is caused by Parcel's (current) tradeoff for build speed instead of bundle size (running terser on the individual files rather than the whole bundle, as already discussed in #2310). webpack takes the other option leading to a smaller bundle.
This can be fixed by making Parcel run terser on the final output bundle instead, actually yielding better results than webpack! :
1.3K parcel.modified.js
2.9K webpack.js
16K parcel.current.js
You can try this yourself by using the experimental Proof-of-Concept @mischnic/parcel-bundler instead of the parcel-bundler package.
@devongovett, in that issue you said:
There also wasn't a very big difference in output size that I saw, but perhaps you've run into something.
Here's an example
This is actually similar to the class example posted in the linked issue by kzc (functions marked as pure aren't eliminated across assets).
I still think tree shaking's primary goal should be bundle size, not build time (given that it's also not enabled by default โ at least currently).
PS: Also, don't rely on the reported build size (normal or --detailed-...) by Parcel when using scope hoisting, it doesn't take tree shaking into account.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.
Most helpful comment
This is caused by Parcel's (current) tradeoff for build speed instead of bundle size (running terser on the individual files rather than the whole bundle, as already discussed in #2310). webpack takes the other option leading to a smaller bundle.
This can be fixed by making Parcel run terser on the final output bundle instead, actually yielding better results than webpack! :
You can try this yourself by using the experimental Proof-of-Concept
@mischnic/parcel-bundlerinstead of theparcel-bundlerpackage.@devongovett, in that issue you said:
Here's an example
This is actually similar to the class example posted in the linked issue by kzc (functions marked as pure aren't eliminated across assets).
I still think tree shaking's primary goal should be bundle size, not build time (given that it's also not enabled by default โ at least currently).
PS: Also, don't rely on the reported build size (normal or
--detailed-...) by Parcel when using scope hoisting, it doesn't take tree shaking into account.