JSPM

@roots/bud-hooks

4.5.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7204
  • Score
    100M100P100Q139017F
  • License MIT

Hooks controller for Bud

Package Exports

  • @roots/bud-hooks

Readme

Bud

MIT License Follow Roots

@roots/bud-hooks

Hooks controller for Bud

Installation

yarn add @roots/bud-hooks

bud.hooks.on

Hooks are registered with bud.hooks.on

bud.hooks.on takes two parameters:

  • The name of the hook.
  • Either a value or a function to filter a value through.

hook usage

A hook can be a reference to a literal value:

bud.hooks.on("build/entry", {
  app: ["app.js"],
});

Or, using a function, we can modify a value that is already hooked.

This example adds new entry to the webpack.externals configuration

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

A hook value doesn't have to already be set in order to register a function, but you will need to guard against type errors yourself:

bud.hooks.on("some-mystery-hook", (value) => ({
  ...(value ?? {}), // use a more robust guard if needed
  key: "value",
}));

bud.hooks.filter

Filters are registered with bud.hooks.filter.

It is a function that takes one parameter: the name of the filter to hook onto.

filter usage

First, a value is registered with bud.hooks.on

// Register a value
const value = ["foo", "bar"];
bud.hooks.on("some-key", value);

// ...

// Later on, retrieve it
const filteredValue = bud.hooks.filter("some-key");

After registration but before it is filtered, the user and/or other extensions now have access to this value and can modify it.

bud.hooks.on("some-key", (value) => value.shift());

Hooks reference

There is a compiled list of hooks used by @roots/bud core available here.

Contributing

Contributions are welcome from everyone.

We have contributing guidelines to help you get started.

Bud sponsors

Help support our open-source development efforts by becoming a patron.

Kinsta KM Digital Carrot C21 Redwood Realty WordPress.com Icons8 Harness Software Coders Clan Genero Motto

Community

Keep track of development and community news.