December 3, 2024
Build extensions
Install system packages, like FFmpeg and Puppeteer, and modify the build process.
Build extensions allow you to install system packages, run container commands, modify package dependencies, use ESBuild plugins, and more.
What can I build with them?
- Transform videos and audio using FFmpeg.
- Control and automate web pages using Puppeteer.
- Manipulate images using Sharp.
- Convert documents using LibreOffice.
- Install any native binaries and use them inside your tasks.
This is a big deal because many system packages don't work in serverless environments, like Vercel.
Using the FFmpeg extension and how it works
To use our official FFmpeg extension you just modify your trigger.config.ts
file to include the extension.
Then in your tasks you can use FFmpeg. In this example, we compress a video using the fluent-ffmpeg library.
Here's a short video from our dashboard of this task running in prod:
How does this work?
The FFmpeg extension uses the onBuildComplete hook, which gets called after ESBuild has packaged the code.
You can add layers which can:
- Modify the Docker image.
- Install system packages using
pkgs
. - Add instructions using
instructions
.
- Install system packages using
- Run commands at the end of the build process using
commands
. - Set environment variables.
Here's the full source code for the FFmpeg extension:
Here's a full example of using FFmpeg to process a video.
Puppeteer
Puppeteer is a headless browser that allows you to interact with web pages. You can use it to take screenshots, generate PDFs, and more.
Use the extension like this:
This very simple task logs out the title of a web page:
IMPORTANT
Please note it's against our Cloud Terms of Service to use Puppeteer to scrape websites where you don't have permission, unless you use a proxy. We recommend using a service like BrowserBase which we have a guide for here.
The source code for the Puppeteer extension is a bit more complicated because it runs a few instructions in the image. But it's still pretty simple.
LibreOffice: how to use aptGet() to install system packages
It's so useful to install system packages that we created the aptGet
extension to make it easier:
Here's how to use LibreOffice to convert documents to PDFs.
ESBuild plugins
We use ESBuild to bundle your task code. It is fast, removes unused code, and has a mature plugin system.
You can add ESBuild plugins using our esbuildPlugin extension, in this case we're using the Sentry ESBuild plugin:
More official build extensions
- Prisma: handles generating the Prisma client.
- Sync env vars: syncs environment variables from another service to Trigger.dev.
- Vercel sync env vars: syncs environment variables from Vercel to Trigger.dev.
- Audio Waveform: generates waveform data and images from audio files.
- Emit decorators: emits metadata for TypeScript decorators, needed for NestJS and MikroORM.
Writing your own extensions
Hopefully I've shown how powerful the build extension system is.
If you want to write your own extension I recommend you read the docs, and view the source code for our official extensions.
If you've built something cool please let us know, we'd love to feature it in our docs or turn it into an official extension.