Check the bundle size of the output build of any package with Vite.
pnpm i --save-dev vite-size
In your package.json add the following script
"size": "npx tsc && vite-size"
As default the script will show you the list of different chunks and their sizes. By using --total
you will get the sum of all the chunks as output.
"size": "npx tsc && vite-size --total"
You can also add external packages so they are not bundled
"size": "npx tsc && vite-size --total --externals <package-name> <another-package-name>"
--externals
should always be the last flag in the script.
To support different frameworks with Vite plugins add the --react
or --vue
flag in the script.
"size": "npx tsc && vite-size --total --react --externals react react-dom"
Use --lib
if you're not using an index.html
file.
"size": "npx tsc && vite-size --total --lib --externals <package-name> <another-package-name>"
pnpm run size
Use with GitHub Actions.