npm-to-cdn

1.0.0 • Public • Published

npm-to-cdn logo npm-to-cdn

Website
GitHub Coverage

A professional open-source Node.js CLI tool to instantly get CDN links for any npm package from major providers.


Features

  • Auto-discovers UMD files from CDN file listings (unpkg, jsDelivr)
  • Supports unpkg, jsDelivr, esm.sh, skypack
  • Minified/dev toggle: --min (default) or --dev
  • Batch mode: Query multiple packages at once
  • Clipboard: Copy first CDN link with --clipboard
  • JSON output: --json for machine-readable output
  • UMD-only: --umd for just unpkg/jsDelivr UMD links
  • Show all versions: --versions flag
  • Verbose/silent: --verbose for debug, --silent for CI
  • Graceful error handling

Installation

npm install -g npm-to-cdn

Usage

n2cdn react
n2cdn lodash@4.17.21
n2cdn axios --json
n2cdn vue --clipboard
n2cdn react@17 lodash@4.17.21 --json --silent
n2cdn react --versions
n2cdn react@17 --umd --verbose
n2cdn vue@2 --dev --umd
n2cdn react --cdnjs
n2cdn react --statically user/repo/tag/dist/file.js
n2cdn react --bowercdn
n2cdn react --template "https://mycdn.com/{name}@{version}/{file}"

Flags

  • --json Output as JSON
  • --clipboard Copy first CDN link to clipboard
  • --umd Show only unpkg/jsDelivr UMD links
  • --min Prefer minified builds (default)
  • --dev Prefer development (non-minified) builds
  • --versions List all available versions for the package
  • --verbose Show all attempted URLs and debug info
  • --silent Suppress banner and only output links
  • --help Show help

Only valid CDN links are shown. UMD guessing is version-aware and auto-discovers from CDN file listings.


Supported CDN Providers

  • unpkg
  • jsDelivr
  • esm.sh
  • skypack
  • cdnjs
  • Statically (GitHub, GitLab, Bitbucket)
  • BowerCDN
  • Custom templates

Usage Examples

n2cdn react --cdnjs
n2cdn react --statically user/repo/tag/dist/file.js
n2cdn react --bowercdn
n2cdn react --template "https://mycdn.com/{name}@{version}/{file}"

CLI Improvements

  • All provider flags are now grouped and clearly documented
  • Input validation for statically flag
  • Consistent flag naming and help output

Example Output

$ n2cdn react@17 lodash@4.17.21 --json --silent
[
  {
    "pkg": "react",
    "version": "17",
    "cdns": {
      "unpkg": "https://unpkg.com/react@17/umd/react.production.min.js",
      "jsDelivr": "https://cdn.jsdelivr.net/npm/react@17/umd/react.production.min.js",
      "esmSh": "https://esm.sh/react@17",
      "skypack": "https://cdn.skypack.dev/react@17"
    }
  },
  {
    "pkg": "lodash",
    "version": "4.17.21",
    "cdns": {
      "esmSh": "https://esm.sh/lodash@4.17.21",
      "skypack": "https://cdn.skypack.dev/lodash@4.17.21"
    }
  }
]

Global Installation

This CLI is globally installable. After running:

npm install -g npm-to-cdn

You can use the n2cdn command anywhere.


Links


License

MIT

Planned Features

  • Support for more CDN providers
  • Custom CDN URL templates via CLI flag

Contributing

See CONTRIBUTING.md for how to get started.

Code of Conduct

This project follows the Contributor Covenant Code of Conduct.

Package Sidebar

Install

npm i npm-to-cdn

Weekly Downloads

5

Version

1.0.0

License

MIT

Unpacked Size

1.19 MB

Total Files

10

Last publish

Collaborators

  • blazeinstall