Migrating an existing static site to Netlify. Easy peasy, but don’t want to keep figuring it out every time.

So here goes.

  1. In the existing repo, install the Netlify CLI: npm i netlify-cli
  2. Create a new site: npx netlify sites:create --manual --with-ci
    1. Select Team
    2. Set Site name
    3. Set build command to bin/hugo/hugo --environment staging -b ${DEPLOY_PRIME_URL}
    4. Set deploy dir to public
    5. Add SSH public key to repo
    6. Set SSH URL
    7. 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"