Parcel: Tree shaking not working with react es6 classes vs functional components

Created on 27 Jan 2020  ยท  9Comments  ยท  Source: parcel-bundler/parcel

๐Ÿ› bug report

Tree shaking is not working properly with react classes (stateful vs functional) components.

This repo https://github.com/mshaaban0/tree-shaker demonstrates the issue clearly for a better understanding.

๐Ÿค” Expected Behavior

Tree shaking should eliminate unused/not imported code from the built bundle.

๐Ÿ˜ฏ Current Behavior

Unused/not imported react classes gets included in the built bundle.

๐Ÿ’ป Code Sample

Playground repo is available here

Bug โœจ Parcel 2 ๐ŸŒณ Tree Shaking

All 9 comments

Could you please try this with Parcel 2?

Hey @mischnic Just did, same results unfortunately.

As suspected, this is related to Babel transpiling the classes.
Parcel 1: modern vs transpiled

@mshaaban0 With Parcel 2, it does work with minification enabled?

@mischnic Nope, just tried it with minification. Same issue.

Could you please update your repo to include only Parcel 2?
I can't find the text StatefulModuleOne in the output.

@mischnic Done.

PR: https://github.com/parcel-bundler/parcel/issues/4046

Terser wasn't configured correctly for the commonjs output format.

@mischnic Thanks for looking into this ๐Ÿ‘

Was this page helpful?
0 / 5 - 0 ratings