package-size is a sweet CLI util, that gives us info about the bundle size of npm packages.
What it does?
Install the packages to a temp directory.
Bundle the packages with webpack and get the bundle size.
Show you the bundle size and cache it by package version.
Get it:npm install -g package-size
Sample usage:
12345678910111213141516171819202122232425262728
# get the size of vue bundlepackage-size vue
# get the size of react+react-dom bundlepackage-size react,react-dom
# get the size of vue react+react-dom preact bundlespackage-size vue react,react-dom preact
# get the size of react+react-dom without using the cachepackage-size react,react-dom --no-cache
# get the size of file in current working directorypackage-size ./dist/index.js
# or a package in current working directory, explictly using `--cwd` flagpackage-size vue --cwd
# or event multiple versions for the same package!package-size [email protected][email protected] react@15
# save results to file system in JSON format# defaults to ./package-size-output.jsonpackage-size cherow --output
# or custom pathpackage-size cherow --output stats.json
# analyze bundle with webpack-bundle-analyzerpackage-size cherow --analyze
1234567891011121314
constgetSizes=require('package-size')getSizes('react,react-dom',options).then(data=>{console.log(data)//=>{name:'react,react-dom',size:12023,// in bytesminified:2342,gzipped:534,versionedName:'[email protected],[email protected]'}})