github-workflows
Contents of the docs

github-workflows · Docs

Prepare Standalone

GitHub Action that completes the standalone output of Next.js with .next/static, public and more folders, so it runs on its own with node server.js.

On this page

prepare-standalone completes the standalone output of Next.js. With output: 'standalone', next build puts a server with the node_modules it needs into .next/standalone, but does not copy the client assets from .next/static and the public folder. The action adds them, so the folder runs on its own with node server.js and the Dockerfile only has to copy it. Node.js Docker CI/CD calls it with standalone: true.

Call

After the build:

- run: npm run build

- uses: DasRed/github-workflows/.github/actions/prepare-standalone@v2
  with:
    paths: |
           .next/static
           public
           content

The matching Dockerfile:

COPY ./.next/standalone /var/www
# package.json separately, because the release bumps the version after the build
COPY ./package.json /var/www/package.json

Inputs

Name Required Default Description
directory no .next/standalone Folder of the standalone output, target of every path in paths
paths no .next/static, public Paths relative to the repository, one per line or separated by comma

Every path in paths ends up at the same path inside directory, so public becomes .next/standalone/public. Folders and single files both work, an existing target is overwritten. Setting paths replaces the default list. Include .next/static and public then.

Checks

  • If directory is missing, the action fails. Usually output: 'standalone' is missing in next.config.
  • A path in paths that does not exist is skipped with a warning.
  • All paths must lie inside the repository. Absolute paths, .. and a path that contains directory itself fail the action.

Switching from your own script

If the project had a postbuild script like scripts/prepare-standalone.ts, put its list of folders into paths and delete the script and postbuild. If it stays, the action just copies the same files a second time. You only need the script if you start the standalone output locally with npm run build && npm start.