A fast, global content delivery network for ES Modules. All modules are transformed to ESM by esbuild in npm.
import React from 'https://esm.sh/react'
import React from 'https://esm.sh/react@17.0.1'
import { renderToString } from 'https://esm.sh/react-dom/server'
import React from 'https://esm.sh/react?target=es2020'
Avaiable target
: es2015 - es2020, esnext
import React from 'https://esm.sh/react?dev'
import React from 'https://esm.sh/postcss-flexbugs-fixes?external=postcss'
import React from 'https://esm.sh/[react,react-dom]/react'
import ReactDom from 'https://esm.sh/[react,react-dom]/react-dom'
or your can define bundle list in the import-map.json
(import-maps proposal)
{
"imports": {
"https://esm.sh/": "https://esm.sh/[react,react-dom]/",
...
}
}
import React from 'https://esm.sh/react' // actual from 'https://esm.sh/[react,react-dom]/react'
import * from 'https://esm.sh/${provider}/name@version/path/to/file'
Avaiable provider
: deno.land, nest.land, x.nest.land, denopkg.com
Simply proxy all the providers in the import-map.json
:
{
"imports": {
"https://deno.land/": "https://esm.sh/deno.land/",
"https://nest.land/": "https://esm.sh/nest.land/",
"https://x.nest.land/": "https://esm.sh/x.nest.land/",
"https://denopkg.com/": "https://esm.sh/denopkg.com/",
...
}
}
esm.sh will polyfill the node internal modules(fs,os,etc) with https://deno.land/std/node
to support some modules to work in Deno, like postcss
:
import postcss from 'https://esm.sh/postcss'
import autoprefixer from 'https://esm.sh/autoprefixer'
const css = (await postcss([ autoprefixer]).process(`
backdrop-filter: blur(5px);
user-select: none;
`).async()).content
By default, esm.sh will response a custom HTTP header of X-TypeScript-Types
when the types(dts) defined, that is useful for deno types check (link).
You can pass the no-check
query to disable the types
header since some types are incorrect:
import unescape from 'https://esm.sh/lodash/unescape?no-check'
Different with Skypack and jspm, esm.sh will bundle all dependencies(exclude peerDependencies) for each package, that means there may be redundant contents transmitted when you are importing multiple packages.
This should be improved when the http/3(quic) is ready. For now the best practice is using the bundle mode.
- Main server in HK
- Global CDN by cloudflare
- China CDN by aliyun
You will need Go 1.14+ to compile the server, and ensure supervisor installed on your host machine.
The server runtime will check the nodejs installation (12+) exists or install the latest LTS version automatically.
$ git clone https://github.com/postui/esm.sh
$ cd esm.sh
$ sh ./scripts/deploy.sh