简体   繁体   English

Webpack插件开发-调用父函数参数的函数

[英]Webpack Plugin Development - function calling an argument of parent function

In the documentation of Webpack this snippet is listed. 在Webpack的文档中,列出了该片段。 I wonder what the callback() function actually does. 我想知道callback()函数实际上是做什么的。

function MyPlugin() {
  this.startTime = Date.now();
  this.prevTimestamps = {};
}

MyPlugin.prototype.apply = function(compiler) {
  compiler.plugin('emit', function(compilation, callback) {

    var changedFiles = Object.keys(compilation.fileTimestamps).filter(function(watchfile) {
      return (this.prevTimestamps[watchfile] || this.startTime) < (compilation.fileTimestamps[watchfile] || Infinity);
    }.bind(this));

    this.prevTimestamps = compilation.fileTimestamps;
    callback();
  }.bind(this));
};

module.exports = MyPlugin;

This is from Webpack@v2, but I believe it explains and applies similarly: 这来自Webpack @ v2,但我相信它可以解释并类似地应用:

https://webpack.js.org/pluginsapi/compiler/ https://webpack.js.org/pluginsapi/compiler/

The Compiler exposes a run method which kickstarts all compilation work for webpack. 编译器公开了一个run方法,它将启动webpack的所有编译工作。 When that is done, it should call the passed in callback function. 完成后,它应该调用传入的回调函数。 All the tail end work of logging stats and errors are done in this callback function. 记录统计信息和错误的所有后端工作都在此回调函数中完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM