Execute JavaScript on any available Webpack event hook
npm install event-hooks-webpack-pluginThis [Webpack][webpack] plugin is similar to [webpack-shell-plugin][webpack-shell-plugin] but it allows executing
arbitrary code instead of commands on any [compiler hook][webpack-compiler-hooks] that is made available by Webpack.
shell
npm install event-hooks-webpack-plugin --save-dev
`Usage
`js
import EventHooksPlugin from 'event-hooks-webpack-plugin';export default {
// ...
plugins: [
new EventHooksPlugin({
initialize: () => {
// ...
}
})
]
};
`Options
The plugin consumes an object with [Webpack compiler event hook names][webpack-compiler-hooks] (e.g. run, compile,
and done) as keys and functions as values.$3
Webpack's compiler uses [Tapable][webpack-tapable] which supports different classes of hooks. This plugin supports
synchronous, promise-based, and callback-based hooks through the exported tap, tapPromise and tapAsync methods.
By default, the plugin uses tap.`js
import EventHooksPlugin, { tapPromise, tapAsync } from 'event-hooks-webpack-plugin';export default {
// ...
plugins: [
new EventHooksPlugin({
emit: tapAsync(() => {
// ...
}),
run: tapPromise(() => {
// ...
})
})
]
};
``[webpack]: https://webpack.github.io/
[webpack-tapable]: https://github.com/webpack/tapable#tapable
[webpack-shell-plugin]: https://www.npmjs.com/package/webpack-shell-plugin
[webpack-compiler-hooks]: https://webpack.js.org/api/compiler-hooks/
[mit-license]: https://opensource.org/licenses/MIT