This webpack plugin is similar to webpack-shell-plugin
but this allows you to execute arbitrary JavaScript instead of commands on any event hook that is exposed by the Webpack compiler.
npm install event-hooks-webpack-plugin --save-dev
const EventHooksPlugin = require('event-hooks-webpack-plugin');
module.exports = {
// ...
plugins: [
new EventHooksPlugin({
eventName: () => {
// ...
}
})
]
};
const EventHooksPlugin = require('event-hooks-webpack-plugin');
module.exports = {
// ...
plugins: [
new EventHooksPlugin({
eventName: new EventHooksPlugin.CallbackTask((compiler, callback) => {
// ...
callback();
})
})
]
};
const EventHooksPlugin = require('event-hooks-webpack-plugin');
module.exports = {
// ...
plugins: [
new EventHooksPlugin({
eventName: new EventHooksPlugin.PromiseTask(async () => {
// ...
})
})
]
};
The plugin consumes an object with webpack compiler event hook names (e.g. run
, compile
, or done
) as keys and functions or task classes as values.