Node Build Step
Often your projects will contain static 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.
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:
You can include environment variables by adding them to the beginning of the command using the standard POSIX format:
NODE_ENV=production npm run build
or by simply including them within your npm script definitions within package.json.
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 and 15.
CUSTOM BUILD IMAGE
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
- OptiPNG, libJPEG, GIFsicle, libPNG, libWEBP, PNGquant, JPEGoptim
- Chromium + necessary packages for headless chrome
- + other related or dependent packages
However, if you require an OS package outside of those that are available by default, you can provide a Custom Build Image which will be used instead. This image should be a container which can be pulled unauthenticated from a remote container registry.
If this is set the NODE VERSION setting will be ignored.
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.
If you are using nystudio107's Craft starter, the following settings can be used to compile static assets:
Command: npm run build
Node Version: N/A, set to anything
Custom Build Image: nystudio107/node-dev-base:14-alpine
Build Context Path: /buildchain