Skip to main content

bud.hooks

bud.hooks allows for modifying values with callbacks. This is useful for things like logging, or for modifying a value before it is used.

bud.hooks.on

Callbacks and raw values are registered with bud.hooks.on

bud.config.js
bud.hooks.on('build.externals', externals => ({
...externals,
$: 'jquery',
})

bud.hooks.on takes two parameters:

  • The name of the hook.
  • A function to filter the associated value through.

bud.hooks.fromMap

Set multiple hooks at once with bud.hooks.fromMap.

bud.hooks.fromMap({
'build.node': false,
'build.resolve.extensions': ext => ext.add('.mjml'),
})

bud.hooks.filter

Filters are registered with bud.hooks.filter.

const result = bud.hooks.filter('my.filter.key', value)

bud.hooks.filter takes two parameters:

  • The name of the filter to hook onto.
  • The value which is being filtered. If there is nothing hooked to this filter, the value will be returned as-is.

bud.hooks.async

Some hooks are asynchronous. An example of this are values for build.resolve.modules:

bud.config.js
bud.hooks.async('build.resolve.modules', async modulePaths => [
...modulePaths,
await fs.promises.realpath('node_modules'),
])

Callbacks for asynchronous hooks should be registered as asynchronous functions.

bud.hooks.fromAsyncMap

Set multiple async hooks at once with bud.hooks.fromAsyncMap.

bud.hooks.fromAsyncMap({
'build.resolve.modules': async paths => [
...paths,
abud.path('@modules'),
],
})

bud.hooks.action

Actions are registered with bud.hooks.action.

bud.hooks.action('my.action.key', async bud => {
bud.log('action log') // do something
})

All actions are asynchronous. The order of execution is not guaranteed.

bud.hooks.fire

Actions are fired with bud.hooks.fire.

await bud.hooks.fire('my.action.key')

This function returns a Promise.