You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/config/extensions/overview.mdx
+303-4Lines changed: 303 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,7 @@ description: "Customize how your project is built and deployed to Trigger.dev wi
6
6
Build extension 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 [trigger.config.ts reference](/config/config-file#extensions) for more information on how to install and use our built-in extensions. Build extensions can do the following:
7
7
8
8
- Add additional files to the build
9
+
- Add dependencies to the list of externals
9
10
- Add esbuild plugins
10
11
- Add additional npm dependencies
11
12
- Add additional system packages to the image build container
@@ -65,16 +66,314 @@ function myExtension(): BuildExtension {
65
66
66
67
## Build hooks
67
68
69
+
### externalsForTarget
70
+
71
+
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.
The path to the lockfile (package-lock.json, yarn.lock, or pnpm-lock.yaml)
274
+
</ResponseField>
275
+
<ResponseFieldname="configFile"type="string">
276
+
The path to the trigger.config.ts file
277
+
</ResponseField>
278
+
<ResponseFieldname="tsconfigPath"type="string">
279
+
The path to the tsconfig.json file
280
+
</ResponseField>
281
+
</Expandable>
282
+
</ParamField>
283
+
284
+
<ParamFieldpath="logger"type="BuildLogger">
285
+
A logger object that can be used to log messages to the console.
286
+
</ParamField>
287
+
288
+
## BuildLayer
289
+
290
+
<ParamFieldpath="id"type="string">
291
+
A unique identifier for the layer.
292
+
</ParamField>
293
+
294
+
<ParamFieldpath="commands"type="string[]">
295
+
An array of commands to run in the image build container.
296
+
297
+
```ts
298
+
commands: ["echo 'Hello, world!'"];
299
+
```
300
+
301
+
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.
302
+
303
+
</ParamField>
304
+
305
+
<ParamFieldpath="image"type="object">
306
+
<Expandabletitle="properties">
307
+
<ResponseFieldname="pkgs"type="string[]">
308
+
An array of system packages to install in the image build container.
309
+
</ResponseField>
310
+
<ResponseFieldname="instructions"type="string[]">
311
+
An array of instructions to add to the Dockerfile.
An object of dependencies to add to the build. The key is the package name and the value is the
338
+
version.
339
+
340
+
```ts
341
+
dependencies: {
342
+
"my-dependency": "^1.0.0",
343
+
};
344
+
```
345
+
346
+
</ParamField>
347
+
348
+
### examples
349
+
350
+
Add a command that will echo the value of an environment variable:
351
+
352
+
```ts
353
+
context.addLayer({
354
+
id: "my-layer",
355
+
commands: [`echo $MY_ENV_VAR`],
356
+
build: {
357
+
env: {
358
+
MY_ENV_VAR: "Hello, world!",
359
+
},
360
+
},
361
+
});
362
+
```
77
363
78
364
## Troubleshooting
79
365
80
-
Describe how to use --dry-run
366
+
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`:
367
+
368
+
```sh
369
+
npx trigger.dev@latest dev --log-level debug
370
+
npx trigger.dev@latest deploy --log-level debug
371
+
```
372
+
373
+
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.
374
+
375
+
```sh
376
+
npx trigger.dev@latest deploy --dry-run
377
+
```
378
+
379
+
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](https://github.com/triggerdotdev/trigger.dev/tree/main/packages/build/src/extensions).
0 commit comments