Decathlon / vitamin-web

Decathlon Design System UI components for web applications
https://decathlon.github.io/vitamin-web
Apache License 2.0
282 stars 76 forks source link

build: add sideEffects false to allow treeshaking #1327

Closed Shyrro closed 1 year ago

Shyrro commented 1 year ago

Signed-off-by: Shyrro zakaria.sahmane@decathlon.com

Changes description

Allow treeshaking by adding sideEffects: false in package.json of every framework. This will allow the callers that use modern bundlers (Webpack 5, Vite, Rollup etc), to only import the components they use instead of everything.

Currently, if we do import { VtmnAccordion } from '@vtmn/react' we will only have one big index.js in the build, whereas we only need the chunk related to the Accordion and its deps.

Context

It reduces perf issues for all apps.

Here is an example of Vitamin in a Next 12 app :

vtmn/react dist in a next app

We can see that Vitamin dist only contains an index.es.js instead of different chunks of used components like the other modules. This is a small app and and we can see that @vtmn/react is taking a lot of space on its own without the ability to load a small portion of it. This change would allow the bundler to understand that the package is written in ESM and that it can treeshake it without worrying about anything.

Checklist

Does this introduce a breaking change?

Other information

This is a small change that can improve everyones lives when working with esm

CLAassistant commented 1 year ago

CLA assistant check
All committers have signed the CLA.

lauthieb commented 1 year ago

Hi @Shyrro, thanks a lot for this contrib! As @thibault-mahe said, I completely missed this (I've just learned this, thanks to you) Approved ✅ @thibault-mahe I let you merge this.