Get started with Build Event Handlers
This page will help you get started with creating an integration that uses Build Event Handlers. It describes how to generate the boilerplate code, what the required files and basic scaffolding are, and how to build your build event handler.
Prerequisites
Windows users should run the Netlify SDK through WSL 2
Support for using the Netlify SDK on Windows is currently only available through WSL 2.
- Node.js 18 or later
- Netlify CLI
- TypeScript
Create a build event handler
-
To get started, run the following command to create a new integration:
-
Then, follow the prompts to add the
Build Event Handler
boilerplate.The Netlify SDK will scaffold the basic structure needed for your build event handler which includes these required files:
src/index.ts
package.json
The
src/index.ts
file is the entrypoint for your integration and is listed in themain
property of yourpackage.json
. -
Inside the
src/index.ts
file, declare an instance ofNetlifyIntegration
and call the methodaddBuildEventHandler
to create your first build event handler.
Customize the enablement flow
As outlined in the enablement flow doc, integrations have access to an onEnable
method that runs after a user enables a published integration in the Netlify UI. You can add logic to customize the flow as needed.
Develop your build event handler
Now that you’ve added a Build Event Handlers component to your integration, you can tailor it to fit your needs.
- Hook into build events throughout the build-deploy lifecycle.
- Use values and methods to develop the logic for your build event handler.
- Call an API handler from your build event handler to interact with the Integration API or Netlify API.
- Debug and test your build event handler to make sure it works as expected.
Build your build event handler
Once you’re done developing your build event handler, you can compile your code by using the following Netlify SDK utility tools command:
The code is compiled to the folder .ntli
.
Next steps
- If your integration requires configuration values from the user, use the Integration UI component to create an interactive surface for user input.
- Learn how to publish your integration so that users can enjoy your build event handler.