react-workspaces/react-workspaces-playground

Tree shaking

andrewmclagan opened this issue · 5 comments

-- This issue is theory and has not been tested --

From a first inspection of this monorepo setup it seems that components would not be tree shakable. Importing <CompOne /> also imports <CompTwo /> as there is nothing specifying webpack (any bundler) should do otherwise.

If we have two apps that both use components, and only need to use portions of these components, we have allot of dead code. In any real-world app/team not all components would be used.

Prime use-case for sideEffects.

Im making allot of assumptions:

  • react-scripts does not have optimisations for transpiling/building packages.
  • react-scripts does not transpile modules in node_modules

@andrewmclagan do you know if this project is still being maintained?

I tried tree-shaking with this a while back, and it worked.
Have you checked the output of the build?

@andrewmclagan - I tested tree shaking just now and it still seems to work just fine.

CleanShot 2019-12-22 at 22 16 33@2x

Anyone: feel free to reopen this if you find a case where tree-shaking is not working.

I'm experiencing an issue where a dependency that a shared component needs will be included in the projects that don't use that component.

So if CompOne imports some-package then that package gets included in the build for some-app even though CompOne isn't used by some-app.