0.1.4 • Published 1 year ago

@hyrious/import-cost v0.1.4

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

@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:2

API

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 the node_modules folder.
  • 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 by path will be excluded.
  • Returns: {PromiseObject}
    • 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

License

MIT @ hyrious