Hosting a static website
After tearing my hair out trying to get Amazon S3 to play nicely with CloudFront to serve my static website, I switched to Netlify. Here's my set-up:
In netlify.toml
:
[build]
command = "npm ci && npm run build"
publish = "_public"
In package.json
:
{
"scripts": {
"build": "rm -rf _public && cp -R static _public && esbuild src/main.js --bundle --minify --outdir=_public/assets",
"serve": "python3 -m http.server -b localhost -d _public 9999"
}
}
Static files (HTML and CSS) live in static/
. JavaScript files live in src/
. Any requests to /
are served by static/index.html
.
Netlify automatically deploys the site when the GitHub repository is pushed to. It was painless to set up a custom domain with HTTPS, too.