Gathering detailed insights and metrics for import-size
Gathering detailed insights and metrics for import-size
Gathering detailed insights and metrics for import-size
Gathering detailed insights and metrics for import-size
babel-plugin-transform-imports-api
Convert import default package API to modular reference to reduce package size and transforms member style imports.
rollup-plugin-analyzer
Mad metrics for your rollup bundles, know all the things
eslint-plugin-small-import
ESLint rule for preventing the full import of big libraries when just a part of it can be imported.
swc-plugin-transform-import
swc plugin for transforming import path to optimize bundle size
Measure the real, minified, tree-shaken impact of individual imports into your app
npm install import-size
Typescript
Module System
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
131 Stars
12 Commits
2 Forks
3 Watchers
11 Branches
2 Contributors
Updated on Feb 01, 2025
Latest Version
1.0.2
Package Id
import-size@1.0.2
Unpacked Size
11.85 kB
Size
4.98 kB
File Count
5
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
Measure the real, minified, tree-shaken impact of individual imports into your app
npx import-size <dependency> <imports>
. For example:
npx import-size immer produce enablePatches
npx import-size --report immer produce enableES5 enablePatches enableMapSet
If you want to generate reports as part of your tooling, you might want to import-size
as development dependency using yarn
or npm
.
This tool is basically the result of a long-winded twitter thread. A long story short: this tool will calculate how many bytes a dependency costs, after bundling it for production and apply-ing treeshaking, based on the things you actually want to import.
import-size
fixes that and comes as a convenient CLI tool. It wraps the excellent import-cost package (also available as VS Code plugin). This tool will create a mini project, that imports precisely the requested imports using production tree-shaking settings.
This is not only useful to monitor your app's size budget, but also when you are maintaining a library. Especially in "report" mode, see below
1$ npx import-size mobx autorun observable computed action 213337
Using only autorun
, observable
, computed
and action
from "MobX" will result in 13 KB (gzipped) being added to your bundle
1$ npx import-size mobx '*' 215850
Importing the full MobX api will take 2KB more (so clearly it is not super good at tree-shaking (yet!))
You can also point the tool at any local directory that contains a module source.
For example, running npx import-size . autorun
in the MobX directory will measure the size of autorun
in the directory in which you run this command.
(Do make sure that the library has been build locally in the latter case)
To measure the size of a default export, just pass in default
as method name.
To measure the size of all exports, pass in *
. To prevent bash expanding this into a bunch of file names, you will typically have to quote it like: '*'
.
The sizes displayed are gzipped and include transitive dependencies (regardless whether these deps are shared with other libs). Sizes are always a few (~20) bytes off due to utility code that is injected.
Report mode can break down the costs of a library as you import more and more of it's features:
1$ import-size --report immer produce enableES5 enablePatches enableMapSet 2 3Import size report for immer: 4┌────────────────────────┬───────────┬────────────┬───────────┐ 5│ (index) │ just this │ cumulative │ increment │ 6├────────────────────────┼───────────┼────────────┼───────────┤ 7│ import * from <module> │ 6684 │ 0 │ 0 │ 8│ produce │ 4024 │ 4024 │ 0 │ 9│ enableES5 │ 2428 │ 4895 │ 871 │ 10│ enablePatches │ 1840 │ 5666 │ 771 │ 11│ enableMapSet │ 4915 │ 6489 │ 823 │ 12└────────────────────────┴───────────┴────────────┴───────────┘ 13(this report was generated by npmjs.com/package/import-size)
The report mode first reports the cost of doing a 'side effect import' and a '*'
(everything) import.
The rows after that show the import sizes of all mentioned imports:
So the above report shows that just importing enablePatches
from 'immer' will cost you 1840
bytes. But, it will cost only an additional 871
bytes if you are already importing produce
and enableES5
anyway. In other words, if you just use produce
from Immer it will arrive at 4KB, and the three additional opt-in features will all come at roughly 1 additional KB (note that those numbers are not accurate for Immer, they are just a demonstration).
Also note that the order of arguments does matter for the cumulatives and increment columns, so you typically want to put the imports in an order that make sense to future library users. Reports like these might be useful in documentation.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
project is archived
Details
Reason
Found 1/12 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
44 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More