0.1.3 β€’ Published 2 years ago

dep-bundle-size v0.1.3

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

dep-bundle-size is a CLI client for BundlePhobia that scans the dependencies in package.json and shows the performance impact of each dependency, and supports monorepo such as pnpm workspaces, yarn workspaces, npm workspaces.

Features

  • πŸ‘€ Auto scan package.json
  • πŸ› οΈ Work with single package, pnpm workspaces, yarn workspaces and npm workspaces
  • ⛓️ Constraint bundle size at dependency installation
  • πŸ’‘ Use actual installed version of the dependency to analyze
  • πŸ’₯ Display detailed scan results
  • πŸ’Ž Use the @clack/prompts for beautiful UI

How to install

pnpm add -g dep-bundle-size

// Or use it as dev dependency of a project
pnpm add dep-bundle-size -D

Usage

dep-bundle-size

Usage:
  $ dep-bundle-size [...packages]

Commands:
  [...packages]
  add <...packages>

For more info, run any command with the `--help` flag:
  $ dep-bundle-size --help
  $ dep-bundle-size add --help

Options:
  -i, --interactive  Select packages to scan
  -r, --recursive    Scan packages in every project of monorepo
  -d, --dir [dir]    Specify project root directory
  -h, --help         Display this message
  -v, --version      Display version number
  • dep-bundle-size will scan all dependencies under the project by default, We can manually select the dependencies to be scanned via --interactive option:
β—‹  Select packages to scan.
β”‚  classnames, react-dom
β”‚
β—‹  Scan ./ completed
╔════════════════════════════════════════════════════════════════════════╗
β•‘                              Scan Results                              β•‘
β•Ÿβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β•’
β•‘ Name             β”‚ MIN      β”‚ MIN + GZIP β”‚ SLOW 3G       β”‚ EMERGING 4G β•‘
β•Ÿβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β•’
β•‘ classnames@2.3.2 β”‚ 717.00B  β”‚ 431.00B    β”‚ 8ms           β”‚ 481ΞΌs       β•‘
β•Ÿβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β•’
β•‘ react-dom@18.2.0 β”‚ 130.48kB β”‚ 41.99kB    β”‚ 0.8398046875s β”‚ 48ms        β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•§β•β•β•β•β•β•β•β•β•β•β•§β•β•β•β•β•β•β•β•β•β•β•β•β•§β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•§β•β•β•β•β•β•β•β•β•β•β•β•β•β•
  • In addition to --interactive. We can also specify the packge to be scanned directly:
$ dep-bundle-size classnames react-dom

dep-bundle-size will get the actual installed version of the scanned dependencies under the project, and if a dependency is not installed, we will request the size information of the latest version instead.

dep-bundle-size add

Usage:
  $ dep-bundle-size add <...packages>

Options:
  -w, --warning    Use warning instead throw an error if
  -d, --dir [dir]  Specify project root directory
  -h, --help       Display this message

The add command is mainly used to limit the size of installed dependencies. We can configure size limits(bytes) in package.json:

{
  "name": "@pkg/foo",
  "dependencies": {},
  "bundle-phobia": {
    "max-size": 10,
    "max-gzip-size": 100
    "max-overall-size": 1000000
    "max-overall-gzip-size": 1000000
  }
}

When installing dependencies(eg.dep-bundle-size add react react-dom), we will first check if the dependencies meets the configured constraints, and if it does not, an error will be reported directly:

$ dep-bundle-size add styled-components

β—“  Checking constraints
Error:  Error: Can not install styled-components@5.3.6(33.39kB), Since their max-size is larger than the configured(10.00B).

If we want to continue the installation if the constraints are not met, we can use the --warning option so that dep-bundle-size will automatically detect the package manager used by the project to complete the installation of the dependencies:

$ dep-bundle-size add styled-components -w

β—“  Checking constraints
Warn:  Can not install styled-components@5.3.6(33.39kB), Since their max-size is larger than the configured(10.00B).
β”‚
β—‹  Checking constraints completed
Info:  Add deps(npm install styled-components)

Credits

This project is highly inspired by bundle-phobia-cli and uses BundlePhobia as backend service , thanks to these awesome projects. β™ͺ(ο½₯Ο‰ο½₯)οΎ‰

License

MIT License