Skip to main content
Node Build Step
Matt Gray avatar
Written by Matt Gray
Updated over 3 months ago

Often your projects will contain front-end assets which require compilation or minifying as part of the deployment process to avoid the need to check the compiled assets into the git repo.

On Servd, this should be completed as part of the bundle creation process.

To help with this Servd provides an optional build step called the Node Build Step. This step allows you to run arbitrary node-based commands against your git repo contents in order to prepare them for deployment.

npm install

Servd will automatically run `npm install` for you so there's no need to include it as part of your command. Servd will also cache the `node_modules` folder after this process has completed so that it doesn't have to be repeated during every new bundle build. This cache is busted if you make any changes to `package.json` `package-lock.json` `.npm*` or the content of the `node_packages` folder.

Including Custom or Filesystem Stored Modules

If your package.json file references any local modules or packages which are checked into the git repo, they need to be placed within a folder called 'node_packages' within the Build Context Path (see below) of your git repo.

E.G, if your Build Context Path is `/`, place any relatively referenced node modules within `/node_packages` within your git repo. If your Build Context Path is `/buildchain`, place any relatively referenced node modules within `/buildchain/node_packages`.

Once your files are in the correct location update your `package.json` to point to them as required.

Configuration

COMMAND

The command that will be executed in order to compile your assets. This can be a script defined in package.json:

`npm run build-production`

or a binary which has been downloaded as part of the npm install process:

`npx webpack build`

or a script which has been checked into your git repo and set to be executable:

`./build-production.sh`

NODE VERSION

The version of node that you would like to use to run your build step. You should try to match this as closely as possible to the version you have been using during development. Servd currently supports versions 10, 12, 14, 15, 16, 17, 18 and 20.

BUILD CONTEXT PATH

By default, Servd will attempt to run your buildchain from the root of the git repo. This requires your `package.json` to be placed at `/package.json` within the repo's folder structure. If your buildchain files are stored within a subfolder in the repo you can supply a build context path which instructs Servd to run all of the relevant command with the working directory that you specify.

If you make use of this feature, please ensure that all relative paths within the buildchain logic match those seen within the git repo.

BUILD ORDER

This field determines whether the node step should be run before or after the PHP composer packages are installed. By default the command is run before composer, but if your node step utilises the composer packages (e.g. Tailwind might need to scan a composer package for CSS classes) then you may want to configure it to run after.

ENVIRONMENT VARIABLES

Servd builds your project's bundles in a completely separate environment to your runtime environment so it doesn't automatically inherit the environment variables supplied on the [Staging|Production] > Settings pages.

If your node build command requires any environment variables to be defined, you can add them here.

Custom Build Images

Servd's node build environment comes with several tools installed which cover the vast majority of asset compilation use cases. Specifically it has:

  • Compiler tools

  • Git

  • openSSH

  • python

  • OptiPNG, libJPEG, GIFsicle, libPNG, libWEBP, PNGquant, JPEGoptim

  • Chromium + necessary packages for headless chrome

  • libsaas

  • + other related or dependent packages

However, if you require an OS package outside of those that are available by default, we can also hook up a custom container instead. This image should be a container which can be pulled unauthenticated from a remote container registry.

If you would like to make use of a custom node build step image, reach out and we can double check that the image looks good before adding it in for you.

Did this answer your question?