0

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...");
  });
CodyBugstein
  • 21,984
  • 61
  • 207
  • 363
  • this is more of a question to be wrote on their repository than wrote here, ask directly on their issues, nobody that actually knows the answer usually comes here – PlayMa256 Sep 04 '18 at 17:59
  • My thinking/hope is that someone with a lot of experience in Webpack will know the reason based on some facts that a beginner like me is not aware of – CodyBugstein Sep 04 '18 at 18:09
  • The "new" .plugin architecture is sort of new, it came with the new 4.0 release. Give it a try opening an issue there, maybe yourself could answer this question and contribute with everyone – PlayMa256 Sep 04 '18 at 18:11

0 Answers0