esm.sh provides a global fast CDN publicly which is powered by Cloudflare. You can also host esm.sh service by yourself. To do this, please follow the instructions below.
- Linux system (Debian/Ubuntu)
- 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,
"npmRegistry": "https://registry.npmjs.org/",
"npmToken": "******"
}
You can find all the server options in config.example.jsonc.
You will need Go 1.22+ to compile and run the server.
go run main.go --config=config.json
Then you can import React
from http://localhost:8080/react.
You can deploy the server to a single machine with the deploy.sh script.
# first time deploy
./scripts/deploy.sh --init
# update the server
./scripts/deploy.sh
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:v136 # specific version
Run the container:
docker run -p 80:80 \
-e NPM_REGISTRY=https://registry.npmjs.org/ \
-e NPM_TOKEN=****** \
ghcr.io/esm-dev/esm.sh:latest
Available environment variables:
COMPRESS
: Compress http responses with gzip/brotli, default istrue
.CUSTOM_LANDING_PAGE_ORIGIN
: The custom landing page origin, default is empty.CUSTOM_LANDING_PAGE_ASSETS
: The custom landing page assets separated by comma(,), default is empty.CORS_ALLOW_ORIGINS
: The CORS allow origins separated by comma(,), default is allow all origins.LOG_LEVEL
: The log level, available values are ["debug", "info", "warn", "error"], default is "info".MINIFY
: Minify the built JS/CSS files, default istrue
.NPM_QUERY_CACHE_TTL
: The cache TTL for NPM query, default is 10 minutes.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.SOURCEMAP
: Generate source map for built JS/CSS files, default istrue
.STORAGE_TYPE
: The storage type, available values are ["fs", "s3"], default is "fs".STORAGE_ENDPOINT
: The storage endpoint, default is "~/.esmd/storage".STORAGE_REGION
: The region for S3 storage.STORAGE_ACCESS_KEY_ID
: The access key for S3 storage.STORAGE_SECRET_ACCESS_KEY
: The secret key for S3 storage.
You can also create your own Dockerfile based on ghcr.io/esm-dev/esm.sh
:
FROM ghcr.io/esm-dev/esm.sh:latest
ADD ./config.json /etc/esmd/config.json
CMD ["esmd", "--config", "/etc/esmd/config.json"]