We typically think of npm as a package manager for node modules written in plain JS that will run without any compilation, but npm is actually built to support the publishing of compiled and packaged assets. This is useful for compiling CoffeeScript or transpiling ES2015. In fact, npm allows us to publish anything. So lets publish our client-side assets there too.
unpkg is a CDN that runs in front of npm. Any package
published on npm is available through unpkg. Assets are accessed through URLs
using this simple format:
https://unpkg.com/package@version/file. For example,
- Generate a UMD package using your favorite build tool.
- Add your packaged assets to
.gitignoreso it’s not commited to git.
- Add your packaged assets to the
package.jsonso they’re part of the package published to npm.
It’s simple and beautiful. unpkg is now my preferred CDN.