npmcdn is a CDN for packages that are published via npm. Use it to quickly and easily load files using a simple URL like https://npmcdn.com/package@version/path/to/file
.
A few examples:
You may also use a tag or version range instead of a fixed version number, or omit the version/tag entirely to use the latest
tag.
If you omit the file path, the main module will be returned. This is especially useful for loading libaries that publish a UMD build as their main module.
If you use the special /bower.zip
file path in a package that contains a bower.json
file, a zip file will be created on the fly that Bower can use to install the package.
Please note: We do NOT recommend JavaScript libraries use Bower. Bower places additional burdens on JavaScript package authors for little to no gain. npmcdn is intended to make it easier to publish code, not harder, so Bower support will be removed in January 2017. Please move to npm for installing packages and stop using Bower before that time. See here for our rationale.
Name | Default Value | Description |
---|---|---|
main |
main |
The name of the field in package.json to use as the main entry point when there is no file path in the URL. This value may be dot-separated to specify a nested field (e.g. ?main=config.browserMain ). |
For npm package authors, npmcdn relieves the burden of publishing your code to a CDN in addition to the npm registry. All you need to do is include your UMD build in your npm package (not your repo, that's different!).
You can do this easily using the following setup:
umd
(or dist
) directory to your .gitignore
file.npmignore
file that does not list the umd
directory. If you don't have an .npmignore
, npm will attempt to ignore everything in your .gitignore
when you npm publish
umd
directory just before you publish. Your first thought might be to use npm's prepublish
script for that, but I'd recommend you just use a separate build script, like this one because prepublish can also run when you don't expect it tonpm publish
you'll have a version available on npmcdn as wellIf you think this is useful, I'd love to hear from you. Please reach out to @mjackson with any questions/concerns.
Also, please feel free to examine the source on GitHub.