Skip to content

Latest commit

 

History

History
95 lines (69 loc) · 2.86 KB

HOSTING.md

File metadata and controls

95 lines (69 loc) · 2.86 KB

Self-Hosting

esm.sh provides a global fast CDN publicly which is powered by Cloudflare. You can also host esm.sh service by yourself.

Clone the Source Code

git clone https://github.com/esm-dev/esm.sh
cd esm.sh

Configuration

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.)

Run the Server Locally

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.

Deploy the Server to a Single Machine

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 and supervisor installed
  • 4x CPU cores or more
  • 8GB RAM or more
  • 100GB disk space or more

Deploy with Docker

Docker Image

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 is false.
  • DISABLE_SOURCEMAP: Disable generating source map for build JS/CSS files, default is false.
  • MINIFY: Minify the build JS/CSS files, default is true.
  • 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"]