I'm using AntD and dealing with huge bundle results. I know for a fact that Vite does tree shaking by default and antD should be compatible with it.
But if for example you create a vite app, install and and import only a Button
component your bundle will be huge:
npm create vite@latest test -- --template react && cd test
npm install antd
Button
inside ./src/app.jsx
and use it somewhere.npm run build
and see the total amount of bundle.In my case it is something like this:
> vite build
vite v5.0.12 building for production...
✓ 1308 modules transformed.
dist/index.html 0.39 kB │ gzip: 0.27 kB
dist/assets/index-mnVFW9LP.js 267.99 kB │ gzip: 88.34 kB
✓ built in 3.73s
Considering that by default the Vite boilerplate will have 142kb, if we rest that to 268 we still have 126kb for a single button. Is this fine or maybe vite is not doing the tree shaking?
Thanks in advance for any help or insights!
Well after a test, the Button
from antd
actually adds up 126kb
to the build.
You can test it by importing more than one component or by importing directly from files. Exemple :
import { Button } from 'antd'
-> 269.45kb
import Button from '../node_modules/antd/es/button/button'
-> 269.45kb
If you add for example the BreadCrumbs
the bundle will grow again. Vite
is doing well the tree shaking, it's just the component of antd
which are massive.