Skip to main content

ESM

A fast, global content delivery network and package manager for ES Modules. All modules are transformed to ESM by esbuild from npm.

Import from URL

import React from 'https://esm.sh/react'

Specify version

import React from 'https://esm.sh/react@16.13.1'

Submodule

import { renderToString } from 'https://esm.sh/react-dom/server'

Specify ESM target

import React from 'https://esm.sh/react?target=es2020'

Development mode

import React from 'https://esm.sh/react?dev'

Bundle mode

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'

⚠️ The bundling packages in URL are litmited up to 10, to bundle more packages, please use esm client.

ESM Client in Deno [WIP]

# install esm command
deno install --allow-read --allow-write --allow-net -n esm https://deno.land/x/esm/cli.ts

# add some modules
$ esm add react react-dom

# specify version or tag
$ esm add react@16.13.1
$ esm add react@next

# remove some modules
$ esm remove lodash

# update installed modules to latest version
$ esm update

# help message
$ esm -h

X-Typescript-Types

esm.sh will response a custom HTTP header of X-TypeScript-Types if the types defined, that is useful for deno types check (link).

figure #1

Caveat

Different with Skypack and jspm, esm.sh will bundle all dependencies(exclude peerDependencies) for each packages, 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.

Self-Hosting

You will need Go 1.14+ to compile the server, and ensure the 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