Customize how your project is built and deployed to Trigger.dev with your own custom build extensions
Build extensions allow you to hook into the build system and customize the build process or the resulting bundle and container image (in the case of deploying). See our build extension overview for more information on how to install and use our built-in extensions. Build extensions can do the following:
Add additional files to the build
Add dependencies to the list of externals
Add esbuild plugins
Add additional npm dependencies
Add additional system packages to the image build container
Add commands to run in the image build container
Add environment variables to the image build container
Sync environment variables to your Trigger.dev project
Build extensions are added to your trigger.config.ts file, with a required name and optional build hook functions. Here’s a simple example of a build extension that just logs a message when the build starts:
You can also extract that out into a function instead of defining it inline, in which case you will need to import the BuildExtension type from the @trigger.dev/build package:
You’ll need to add the @trigger.dev/build package to your devDependencies before the below
code will work. Make sure it’s version matches that of the installed @trigger.dev/sdk package.
This allows the extension to add additional dependencies to the list of externals for the build. This is useful for dependencies that are not included in the bundle, but are expected to be available at runtime.
This hook runs after the build completes. It receives the BuildContext object and a BuildManifest object as arguments. This is where you can add in one or more BuildLayer’s to the context.
An array of commands to run in the image build container.
Copy
Ask AI
commands: ["echo 'Hello, world!'"];
These commands are run after packages have been installed and the code copied into the container in the “build” stage of the Dockerfile. This means you cannot install system packages in these commands because they won’t be available in the final stage. To do that, please use the pkgs property of the image object.
Environment variables to add to the image build container, but only during the “build” stage
of the Dockerfile. This is where you’d put environment variables that are needed when running
any of the commands in the commands array.
Environment variables that should sync to the Trigger.dev project, which will then be avalable
in your tasks at runtime. Importantly, these are NOT added to the image build container, but
are instead added to the Trigger.dev project and stored securely.
When creating a build extension, you may run into issues with the build process. One thing that can help is turning on debug logging when running either dev or deploy:
Copy
Ask AI
npx trigger.dev@latest dev --log-level debugnpx trigger.dev@latest deploy --log-level debug
Another helpful tool is the --dry-run flag on the deploy command, which will bundle your project and generate the Containerfile (e.g. the Dockerfile) without actually deploying it. This can help you see what the final image will look like and debug any issues with the build process.
Copy
Ask AI
npx trigger.dev@latest deploy --dry-run
You should also take a look at our built in extensions for inspiration on how to create your own. You can find them in in the source code here.
Assistant
Responses are generated using AI and may contain mistakes.