Effortlessly empower your project with typed hooks, enabling you to easily construct a plugin API for your needs.
npm install hooxs
import { createHooks } from "hooxs";
interface RuntimeHooks {
"build:before": () => void;
"build:after": (files: string[]) => void;
// can either be registered inside the hooks object or registered at a later point
"config:load"?: (config: Record<string, unknown>) => void;
}
const hooks = createHooks<RuntimeHooks>({
"build:before": () => {
console.log("before build");
},
"build:after": (files) => {
console.log("after build", files);
},
});
// or initialize hooks at a later point
const hooks = createHooks<RuntimeHooks>();
hooks.on("config:load", (config) => {
console.log("config loaded", config);
});
await hooks.call("build:before");
const files = ["index.js", "index.css"];
await hooks.call("build:after", files);
Published under MIT License.