unpkg/modules/client/components/Home.md

3.6 KiB

unpkg is a fast, global content delivery network for stuff that is published to npm. Use it to quickly and easily load files using a simple URL like:

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, unpkg will try to serve the browser bundle if present, the main module otherwise.

Append a / at the end of a URL to view a listing of all the files in a package.

You may use the special /bower.zip file path in packages that contain a bower.json file to dynamically generate a zip file that Bower can use to install the package.

We do NOT recommend JavaScript libraries use Bower. Bower places additional burdens on JavaScript package authors for little to no gain. unpkg 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.

Query Parameters

Name Default Value Description
`main` `unpkg`, `browser`, `main` The name of the field in [package.json](https://docs.npmjs.com/files/package.json) to use as the main entry point when there is no file path in the URL.
`json` `undefined` Return a recursive list of metadata about all the files in a directory as JSON (e.g. `/any/path/?json`). Note: this only works for directories.

Suggested Workflow

For npm package authors, unpkg 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:

  • Add the umd (or dist) directory to your .gitignore file
  • Add the umd directory to your files array in package.json
  • Use a build script to generate your UMD build in the umd directory when you publish

That's it! Now when you npm publish you'll have a version available on unpkg as well.