esm.sh provides a fast, global content delivery network publicly which powered by Cloudflare. You may also want to host esm.sh by yourself.
To serve esm.sh, You will need Go 1.18+ to run and compile the server. The server will install Node.js runtime automatically if it's not found on your host machine.
- Linux system with git installed
- 4x CPU cores or more
- 8GB RAM or more
- 100GB disk space or more
git clone https://github.com/esm-dev/esm.sh
cd esm.sh
To configure the server, create a config.json
file then pass it to the server
bootstrap command. For example:
// config.json
{
"port": 8080,
"workDir": "/var/www/esmd",
"storage": "local:/var/www/esmd/storage",
"origin": "https://esm.sh",
"npmRegistry": "https://registry.npmjs.org/",
"npmToken": "xxxxxx"
}
You can find all the server options in
config.exmaple.jsonc. (Note: the
config.example.jsonc
is not a valid JSON file, it's a JSONC file.)
go run main.go --config=config.json --dev
Then you can import React
from http://localhost:8080/react
Please ensure the supervisor has been installed on your host machine.
./scripts/deploy.sh --init
esm.sh provides an official docker image for deployment. You can pull the container image from https://ghcr.io/esm-dev/esm.sh:
docker pull ghcr.io/esm-dev/esm.sh # latest version
docker pull ghcr.io/esm-dev/esm.sh:v135 # specific version
Then run the container:
docker run -p 8080:8080 \
-e NPM_REGISTRY=https://registry.npmjs.org/ \
-e NPM_TOKEN=xxxxxx \
ghcr.io/esm-dev/esm.sh:latest
Available environment variables:
CDN_ORIGIN
: The origin of CDN, default is using the origin of the request.CDN_BASE_PATH
: The base path of CDN, default is "/".NPM_REGISTRY
: The NPM registry, default is "https://registry.npmjs.org/".NPM_TOKEN
: The NPM token for private packages.NPM_REGISTRY_SCOPE
: The NPM registry scope, default is no scope.NPM_USER
: The NPM user for private packages.NPM_PASSWORD
: The NPM password for private packages.SERVER_AUTH_SECRET
: The server auth secret, default is no auth.
You can also create your own Dockerfile with ghcr.io/esm-dev/esm.sh
:
FROM ghcr.io/esm-dev/esm.sh
ADD ./config.json /etc/esmd/config.json
CMD ["esmd", "--config", "/etc/esmd/config.json"]
We use Cloudflare Workers as the CDN layer to handle and cache esm.sh requests at edge(earth). We open sourced the code, you can use it to build your own esm CDN without deploying the server easily.
More details check esm-worker.
We also provide a server for Deno which is powered by the esm-worker.
deno run -A https://esm.sh/v135/server --port=8080