When creating a webpack plugin, the way one listens to lifecycle events is by calling compiler.plugin
, like this example, which calls the callback function when the compile
event is emitted;
MyPlugin.prototype.apply = function(compiler) {
compiler.plugin("compile", function(params) {
console.log("The compiler is starting to compile...");
});
My question is, why did the Webpack team choose this peculiar naming scheme? As they seem to be using the Event Pattern (aka Observer Pattern), wouldn't it have been much more appropriate to call the function "on
", for instance:
MyPlugin.prototype.apply = function(compiler) {
compiler.on("compile", function(params) {
console.log("The compiler is starting to compile...");
});