Skip to content

electfreak/single-import-cost

Repository files navigation

single-import-cost

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

Installation

npm i electfreak/single-import-cost

Usage

Main 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
}

Testing

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.

Related:

TODO:

  • write tests?
  • publish package?
  • add caching?
  • add some configuration (e.g. whether to calc gzip/brotli)

About

Calculates size of a single JS import using specified bundler

Topics

Resources

Stars

Watchers

Forks