If you want more control over the handling of your function source files, you can use your site’s build command to customize the build process.
Netlify runs your build command before accessing your functions directory to prepare and deploy your functions. This means you can use your build command to override any part of the default preparation process up until the point Netlify deploys executable artifacts.
Here are some examples of customizations you could make to the process:
Bundle your functions with tools not available through Netlify such as Webpack or Rollup.
Run unit tests to validate your functions before they’re deployed.
If you want your custom build to bypass Netlify’s automated function and dependency preparation entirely, your build process needs to result in Node.js ZIP archives in your functions directory. Netlify will deploy these without modification.
To customize the build process, do one of the following:
Include customizations directly in your build command. For example:
This example customizes the TypeScript compilation stage.
Invoke scripts through a file called by your build command. For example:
npm run test:functions &&npm run build
Where test:functions is a unit testing script configured in package.json. For more information, visit our Forums for a verified Support Guide on testing your Netlify builds.
For even more control over the handling of your function source files and dependencies, you can bundle ZIP archives outside of Netlify.
If you put your bundled ZIP archives in your functions directory before you push changes to your Git provider, Netlify will deploy these executable artifacts without modification.
Consider CLI deploys instead
It’s not a best practice to track bundling results in Git. So, if you want to bundle your own ZIP archives, we recommend you use CLI deploys instead of continuous deployment with Git.
If you want more control over the handling of your function source files, you can use your site’s build command to customize the build process.
Netlify runs your build command before accessing your functions directory to prepare and deploy your functions. This means you can use your build command to override any part of the default preparation process up until the point Netlify deploys executable artifacts.
Here are some examples of customizations you could make to the process:
Bundle your functions with tools not available through Netlify such as Webpack or Rollup.
Run unit tests to validate your functions before they’re deployed.
If you want your custom build to bypass Netlify’s automated function and dependency preparation entirely, your build process needs to result in Node.js ZIP archives in your functions directory. Netlify will deploy these without modification.
To customize the build process, do one of the following:
Include customizations directly in your build command. For example:
This example uses Rollup to bundle a specific function.
Invoke scripts through a file called by your build command. For example:
npm run test:functions &&npm run build
Where test:functions is a unit testing script configured in package.json. For more information, visit our Forums for a verified Support Guide on testing your Netlify builds.
For even more control over the handling of your function source files and dependencies, you can bundle ZIP archives outside of Netlify.
If you put your bundled ZIP archives in your functions directory before you push changes to your Git provider, Netlify will deploy these executable artifacts without modification.
Consider CLI deploys instead
It’s not a best practice to track bundling results in Git. So, if you want to bundle your own ZIP archives, we recommend you use CLI deploys instead of continuous deployment with Git.
If you want more control over the handling of your function source files, you can use your site’s build command to customize the build process.
Netlify runs your build command before accessing your functions directory to prepare and deploy your functions. This means you can use your build command to override any part of the default preparation process up until the point Netlify deploys executable artifacts.
Here are some examples of customizations you could make to the process:
Detect source files from several different directories.
Run unit tests to validate your functions before they’re deployed.
If you want your custom build to bypass Netlify’s automated function preparation entirely, your build process needs to result in compiled binaries in your functions directory. Netlify will deploy these without modification.
You can customize go build in one of the following ways.
Include go build directly in your build command. For example:
go build -o netlify/functions/hello ./hello/function.go && go build -o netlify/functions/goodbye ./goodbye/function.go
This example builds source files saved in multiple different directories into compiled binaries in the functions directory for deployment.
Invoke go build through a file called by the build command. For example:
npm run build &&npm run build:function
This example invokes a script stored in package.json. Visit the example repository to explore the full example.
For even more control over the handling of your function source files, you can compile binaries outside of Netlify.
If you put your compiled binaries in your functions directory before you push changes to your Git provider, Netlify will deploy these executable artifacts without modification.
Consider CLI deploys instead
It’s not a best practice to track compilation results in Git. So, if you want to compile your own binaries, we recommend you use CLI deploys instead of continuous deployment with Git.