A fast, global content delivery network for ES Modules.
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/[email protected]'
import { renderToString } from 'https://esm.sh/react-dom/server'
or import non-module(js) files:
import 'https://esm.sh/tailwindcss/dist/tailwind.min.css'
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/[react,react-dom,swr]/react' import ReactDom from 'https://esm.sh/[react,react-dom,swr]/react-dom'
or your can define the bundle list in
import-map.json(import-maps proposal)
{ "imports": { "https://esm.sh/": "https://esm.sh/[react,react-dom,swr]/", ... } }
import React from 'https://esm.sh/react' // actual from 'https://esm.sh/[react,react-dom,swr]/react'
⚠️ The bundling packages in URL are litmited up to 10, to bundle more packages, please use the esm client(WIP).
esm.sh provides polyfills for the node internal modules(fs, os, etc) with
deno.land/std/nodeto support some packages working 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-Typeswhen the types(dts) defined, that is useful for deno types check (link).
You can pass the
no-checkquery to disable the
typesheader if 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.
As optional, you can split code manually with
externalquery:
import React from 'https://esm.sh/[email protected]' import useSWR from 'https://esm.sh/[email protected]'
You will need Go 1.14+ to compile the server, and ensure supervisor installed on your host machine.
The server runtime will install the latest nodejs (14+ LTS) automatically.
$ git clone https://github.com/postui/esm.sh $ cd esm.sh $ sh ./scripts/deploy.sh