esm.sh provides a global fast CDN publicly which is powered by Cloudflare. You can also host esm.sh service by yourself.
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,
"npmRegistry": "https://registry.npmjs.org/",
"npmToken": "xxxxxx"
}
You can find all the server options in config.example.jsonc. (Note: the
config.example.jsonc
is not a valid JSON file, it's a JSONC file.)
You will need Go 1.18+ to compile the server.
go run main.go --config=config.json
Then you can import React
from http://localhost:8080/react.
Ensure the supervisor has been installed on your host machine.
# first time deploy
./scripts/deploy.sh --init
# update the server
./scripts/deploy.sh
Recommended host machine requirements:
- Linux system with
git
,git-lfs
andsupervisor
installed - 4x CPU cores or more
- 8GB RAM or more
- 100GB disk space or more
esm.sh provides a 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
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:
AUTH_SECRET
: The server auth secret, default is no authrization check.DISABLE_COMPRESSION
: Disable http compression, default isfalse
.DISABLE_SOURCEMAP
: Disable generating source map for build JS/CSS files, default isfalse
.MINIFY
: Minify the build JS/CSS files, default istrue
.LOG_LEVEL
: The log level, available values are ["debug", "info", "warn", "error"], default is "info".NPM_REGISTRY
: The global NPM registry, default is "https://registry.npmjs.org/".NPM_TOKEN
: The access token for the global NPM registry.NPM_USER
: The access user for the global NPM registry.NPM_PASSWORD
: The access password for the global NPM registry.
You can also create your own Dockerfile based on ghcr.io/esm-dev/esm.sh
:
FROM ghcr.io/esm-dev/esm.sh:v135_6
ADD ./config.json /etc/esmd/config.json
CMD ["esmd", "--config", "/etc/esmd/config.json"]