Migrating an existing static site to Netlify. Easy peasy, but don’t want to keep figuring it out every time.
So here goes.
- In the existing repo, install the Netlify CLI:
npm i netlify-cli
- Create a new site:
npx netlify sites:create --manual --with-ci
- Select Team
- Set Site name
- Set build command to
bin/hugo/hugo --environment staging -b ${DEPLOY_PRIME_URL}
- Set deploy dir to
public
- Add SSH public key to repo
- Set SSH URL
- Add Webhook
In the netlify.toml
ensure the following is set:
[build]
publish = "public"
# Specify the baseURL here as it is different per branch
command = "bin/hugo/hugo --environment staging -b ${DEPLOY_PRIME_URL}"
[build.environment]
NODE_ENV = "production" # Ensures devDependencies are not installed during Netlify build
[context.production]
command = "bin/hugo/hugo --gc --minify --environment production"
[dev]
command = "bin/hugo/hugo serve --disableFastRender"
port = 1313
[[plugins]]
package = "@netlify/plugin-lighthouse"