Configuring build automation
Build automation lets you run commands to prepare your application before it's deployed to your server.
Use it to:
- Install dependencies with
npm,yarnorcomposer - Compile or bundle frontend assets
- Run application build scripts
- Remove files that aren't needed in production
For example:
build:
- npm install
- npm run build
Launchdeck runs these commands in an isolated build environment before transferring the finished build to your server.
Build
The simplest build configuration is a list of commands. Launchdeck runs each command in order.
build:
- echo "hi"
- sleep 1
- uname
For more control, you can specify options for individual commands. For example, this runs ls from the src directory:
build:
- path: src
cmd: ls
- echo "hi"
Simple and advanced command definitions can be used together in the same build configuration.
Removing files before deployment
You can use purge to remove files or directories after the build has finished but before it is transferred to your server.
This is useful for dependencies and other files that are only needed during the build.
purge:
- "web/node_modules"
- "web/assets"
In this example, Launchdeck removes web/node_modules and web/assets before transferring the build.
Removing unnecessary files can reduce transfer times and storage usage. In particular, consider removing node_modules if it isn't required by your application on the destination server.
Per-command caching
Some build commands, such as installing dependencies, can take a significant amount of time while producing the same output between builds.
Launchdeck can cache the output of individual commands and restore it when the relevant input files haven't changed.
For example:
build:
- path: web
cmd: yarn install
input:
- yarn.lock
- package.json
output:
- node_modules
Here, yarn.lock and package.json are the inputs, while node_modules is the cached output. These paths are relative to the command's working directory.
On the first build, Launchdeck runs yarn install and stores the resulting node_modules directory in the build cache.
On subsequent builds, if yarn.lock and package.json haven't changed, Launchdeck restores node_modules from the cache instead of running the command again.
This can significantly reduce build times.
Special commands
Launchdeck provides two additional commands that can be used during a build.
use-node-version <version> switches to the specified version of Node.js for the remainder of the build.
pull-up <folder> moves the contents of a directory into the build root, removing the other files in the current working directory.
This is useful when a build command generates your finished application in a subdirectory such as build or dist.
For example:
build:
- use-node-version 20
- npm install
- npm run build
- pull-up build
Build automation vs SSH commands
Build automation runs commands in an isolated build environment before your application is transferred to your server.
For commands that need to run on the destination server — such as database migrations, clearing caches or restarting services — use SSH commands instead.
Happy deploying!