import React from 'react'; import PropTypes from 'prop-types'; import { Global, css } from '@emotion/core'; import formatBytes from 'pretty-bytes'; import formatDate from 'date-fns/format'; import parseDate from 'date-fns/parse'; import formatNumber from '../utils/formatNumber'; import formatPercent from '../utils/formatPercent'; import cloudflareLogo from './CloudflareLogo.png'; import herokuLogo from './HerokuLogo.png'; const globalStyles = css` body { font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; line-height: 1.7; padding: 5px 20px; color: #000000; } @media (min-width: 800px) { body { padding: 40px 20px 120px; } } a:link { color: blue; text-decoration: none; } a:visited { color: rebeccapurple; } dd, ul { margin-left: 0; padding-left: 25px; } `; const styles = { heading: { margin: 0, textTransform: 'uppercase', textAlign: 'center', fontSize: '5em' }, subheading: { fontSize: '1.6em' }, example: { textAlign: 'center', backgroundColor: '#eee', margin: '2em 0', padding: '5px 0' } }; function AboutLogo({ children }) { return (
From {formatDate(since, 'MMM D')} to{' '} {formatDate(until, 'MMM D')} unpkg served{' '} {formatNumber(totals.requests.all)} requests and a total of {formatBytes(totals.bandwidth.all)} of data to{' '} {formatNumber(totals.uniques.all)} unique visitors,{' '} {formatPercent(totals.requests.cached / totals.requests.all, 0)}% {' '} of which were served from the cache.
); } export default class App extends React.Component { constructor(props) { super(props); this.state = { stats: null }; if (typeof window === 'object' && window.localStorage) { const savedStats = window.localStorage.savedStats; if (savedStats) { this.state.stats = JSON.parse(savedStats); } window.onbeforeunload = () => { window.localStorage.savedStats = JSON.stringify(this.state.stats); }; } } componentDidMount() { // Refresh latest stats. fetch('/api/stats?period=last-month') .then(res => res.json()) .then(stats => this.setState({ stats })); } render() { const { stats } = this.state; return (unpkg is a fast, global{' '} content delivery network {' '} for everything on npm. Use it to quickly and easily load any file from any package using a URL like:
Using a fixed version:
You may also use a{' '}
semver range or a{' '}
tag instead of a
fixed version number, or omit the version/tag entirely to use the{' '}
latest
tag.
If you omit the file path (i.e. use a “bare” URL), unpkg
will serve the file specified by the unpkg
field in{' '}
package.json
, or fall back to
main
.
Append a /
at the end of a URL to view a listing of all
the files in a package.
?meta
/any/file?meta
)
?module
import
specifiers
{' '}
in JavaScript modules to unpkg URLs. This feature is{' '}
very experimental
The CDN caches files based on their permanent URL, which includes the npm package version. This works because npm does not allow package authors to overwrite a package that has already been published with a different one at the same version number.
URLs that do not specify a package version number redirect to one that
does. This is the latest
version when no version is
specified, or the maxSatisfying
version when a{' '}
semver version is
given. Redirects are cached for 5 minutes.
Browsers are instructed (via the Cache-Control
header) to
cache assets for 1 year.
unpkg is an open source project built and maintained by{' '} Michael Jackson. unpkg is not affiliated with or supported by npm, Inc. in any way. Please do not contact npm for help with unpkg. Instead, please reach out to{' '} @unpkg with any questions or concerns.
The fast, global infrastructure that powers unpkg is generously donated by Cloudflare and{' '} Heroku.
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:
umd
(or dist
) directory to your{' '}
.gitignore
file
umd
directory to your{' '}
files array
{' '}
in
package.json
umd
directory when you publish
That's it! Now when you npm publish
you'll have
a version available on unpkg as well.