Configuration
How to configure esbuild-azure-functions.
How to configure
How you configure esbuild-azure-functions depends on if you are using the CLI or calling programmatically. We recommend calling esbuild-azure-functions programmatically, though.
Configuring on the CLI
By default, esbuild-azure-functions expects a file called esbuild-azure-functions.config.json
in the current working directory. You can, however, specify a file using the -c | --config
flag.
Configuring in the code
If you are calling esbuild-azure-functions programmatically, you can simply pass the config object to the build
or watch
function.
import { build, watch } from 'esbuild-azure-functions';
await build({ /* your config here */ });
// or
await watch({ /* your config here */ });
Properties
These properties are available
Project
Required: yes
Type: string
Default: undefined
Supported by: build
, watch
The root folder of the Azure Functions project you want to build.
import { build } from 'esbuild-azure-functions';
await build({
project: '.'
});
Entry Points
Required: no
Type: string[]
Default: undefined
Supported by: build
, watch
Specify custom entry points if you don't want esbuild-azure-functions to search for index.ts files in the project
folder.
import { build } from 'esbuild-azure-functions';
await build({
project: '.',
entryPoints: [
'my-func/func-file.ts',
'other-func/func-file.ts'
]
});
Exclude
Required: no
Type: string[]
Default: undefined
Supported by: build
, watch
Specify directories as glob patterns to exclude when searching for index.ts files.
import { build } from 'esbuild-azure-functions';
await build({
project: '.',
exclude: [
'**/utils/**'
]
});
Clean
Required: no
Type: boolean
Default: false
Supported by: build
, watch
Specify whether esbuild-azure-functions should delete the output directory before building.
import { build } from 'esbuild-azure-functions';
await build({
project: '.',
clean: true
});
Log Level
Required: no
Type: "off" | "error" | "warn" | "info" | "verbose"
Default: "error"
Supported by: build
, watch
Specify the verbosity of log messages.
import { build } from 'esbuild-azure-functions';
await build({
project: '.',
logLevel: 'verose'
});
esbuild options
Required: no
Type: Refer to official docs
Supported by: build
, watch
Customize the esbuild confg that esbuild-azure-functions uses.
Note: Modifying this can lead to unexpected behavior. You should never set write
to true since esbuild-azure-functions write the output files itself.
import { build } from 'esbuild-azure-functions';
await build({
project: '.',
esbuildOptions: {
minify: false
}
});
Advanced options
Enable some advanced options depending on your environment.
Enable __dirname
Shim
__dirname
ShimRequired: no
Type: boolean
Default: false
Supported by: build
, watch
Enables a plugin that patches __dirname
and __filename
using import.meta.url
(see official Node.js docs) at the top of every output file because they are not available in ESM and esbuild doesn't shim them itself.
import { build } from 'esbuild-azure-functions';
await build({
project: '.',
advancedOptions: {
enableDirnameShim: true
}
});
Enable require
Shim
require
ShimRequired: no
Type: boolean
Default: false
Supported by: build
, watch
Enables a plugin that patches require
using import.meta.url
at the top of every output file because esbuild doesn't support converting CJS requires to ESM imports.
import { build } from 'esbuild-azure-functions';
await build({
project: '.',
advancedOptions: {
enableRequireShim: true
}
});
Callbacks
These callbacks are available to hook into the build process. These are only available when esbuild-azure-functions is used in code.
onRebuild
Required: no
Type: function
Parameters: (error: BuildFailure | null, result: BuildResult | null)
Default: undefined
Supported by: watch
Callback that's called for every rebuild.
import { build } from 'esbuild-azure-functions';
await build({
project: '.',
onRebuild: (error, result) => {
// do something cool here
}
});
Last updated