ctrlplusb / react-universally

A starter kit for universal react applications.
MIT License
1.7k stars 244 forks source link

Tree shaking not working #551

Closed sendlo closed 6 years ago

sendlo commented 6 years ago

I don't see tree shaking working.

I cloned and installed the app. I added a file in the components directory that has 2 exports. In the DemoApp index file I imported one of the exports from the new file. But when I run 'npm run build' the generated index JS file contains both exports.

Do we need to do something different to enable tree shaking? Is there a test to make sure tree shaking is working as expected?

sendlo commented 6 years ago

You can see that it fails using this fork: https://github.com/sendlo/react-universally

Build and then search the client index js file for 'miketest' and you will see that both functions are included in the output, even though only one is being imported.

I tried to find the problem, but couldn't. One of the features of your starter kit is tree-shaking, so I hope you can find the issue.

ctrlplusb commented 6 years ago

Yeah, in fact, tree shaking is supported via Webpack, and prior to v4 its tree shaking feature wasn't as robust as one might have imagined. To be honest I kept forgetting to remove this from our checklist. The good news is that v4 seems to have made big headway with this. I think it all requires that you are using ES module syntax though, so I would recommend you familiarise yourself with their docs on the matter. 👍