storybookjs / design-system

🗃 Storybook Design System
https://master--5ccbc373887ca40020446347.chromatic.com/
1.91k stars 585 forks source link

[Bug] Tree shaking when using the DS library in a host application #346

Open nebarf opened 2 years ago

nebarf commented 2 years ago

Describe the bug

I installed storybook DS as a dependency of a sample React app and verified how it affects the final bundle. At a first glance it seems that the library is not tree-shakable, meaning that importing just a single component of the DS results in the entire library being part of the final bundle.

Steps to reproduce the behavior

You can clone the repo at https://github.com/nebarf/storyboook-ds-tree-shaking and just playing with the commented import and jsx (https://github.com/nebarf/storyboook-ds-tree-shaking/blob/main/src/App.js#L3 and https://github.com/nebarf/storyboook-ds-tree-shaking/blob/main/src/App.js#L11). Screenshots below show how the final bundle does not change by importing and using a different set of library components.

Screenshots

Build 1

build-1-1 build-1

Build 2

build-2-1 build-2

Expected behavior

I would expect the library to be fully tree shakable and having only the imported components being part of the application bundle when the library is consumed.

Environment