0.1.4 • Published 3 years ago
@hyrious/import-cost v0.1.4
@hyrious/import-cost
Get imported code size of a package.
This package is heavily inspired by import-cost.
Usage
CLI
> npx @hyrious/import-cost file.ts
Package Cost Where
lodash 70 kiB file.ts:2API
importCost(path, code, options?)
import { importCost } from '@hyrious/import-cost'
const result = await importCost('file.ts', `
import { uniqueId } from 'lodash'
`)
// => { errors: [], warnings: [], packages: [
// { path: 'file.ts', name: 'lodash', line: 2, size: 70000, gzip: 70000 }
// ] }path{String} The path to the file, this is used for looking up thenode_modulesfolder.code{String} The contents of the file.options{Object}lang{String} Override the language infered from file extension. Available values:js,ts,jsx,tsx,vue,svelte.external{String[]} Override packages to be excluded from the bundle. By default, all peer dependencies scanned from the package.json indicated bypathwill be excluded.
- Returns: {Promise⟨Object⟩}
errors,warnings{Object[]} Passed through from esbuild.packages{Object[]}path{String} The path to the file, same as the input argument.name{String} The name of the analyzed package.line{Number} The line number of the import statement.size{Number} The size of the package in bytes.gzip{Number} The size of the package in bytes after gzip.
cache
import { cache } from '@hyrious/import-cost'
cache.clear()Related Works
- vscode-import-cost: The VS Code extension that uses this package.
License
MIT @ hyrious