npm-to-cdn
v1.0.0
Published
A CLI tool to get CDN links for any npm package.
Maintainers
Readme
npm-to-cdn
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:
--jsonfor machine-readable output - UMD-only:
--umdfor just unpkg/jsDelivr UMD links - Show all versions:
--versionsflag - Verbose/silent:
--verbosefor debug,--silentfor CI - Graceful error handling
Installation
npm install -g npm-to-cdnUsage
n2cdn react
n2cdn [email protected]
n2cdn axios --json
n2cdn vue --clipboard
n2cdn react@17 [email protected] --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
--jsonOutput as JSON--clipboardCopy first CDN link to clipboard--umdShow only unpkg/jsDelivr UMD links--minPrefer minified builds (default)--devPrefer development (non-minified) builds--versionsList all available versions for the package--verboseShow all attempted URLs and debug info--silentSuppress banner and only output links--helpShow 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 [email protected] --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/[email protected]",
"skypack": "https://cdn.skypack.dev/[email protected]"
}
}
]Global Installation
This CLI is globally installable. After running:
npm install -g npm-to-cdnYou 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.
