This package provides an utility which bundles a dummy project with a single import to estimate the size of a given import. Calculates size of tree-shaken, minified code.
Under development.
Uses:
- esbuild/rollup with few plugins
- TypeScript
npm i electfreak/single-import-costMain function is located in index.ts. To call it:
import singleImportCost from "single-import-cost";
singleImportCost(
importData: ImportData,
bundler: Bundler, // esbuild by default
timeoutMs: number // 3'000 by deafult
)
interface ImportData {
filePath: string; // path to file with import
importString: string; // import taken from this file with some usage of imported modules
importPath: string; // import specifier
}Was tested with VSCode extension tests (see below) – easy to to adapt to them. Most tests didn't show significant difference from those import-cost implementation. No own tests for now.
- VSCode import-cost (initial inspiration)
- Used by plugin for intellij
TODO:
- write tests?
- publish package?
- add caching?
- add some configuration (e.g. whether to calc gzip/brotli)