Reputation: 725
In the documentation of Webpack this snippet is listed. I wonder what the callback() function actually does.
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;
Upvotes: 0
Views: 209
Reputation: 1403
This is from Webpack@v2, but I believe it explains and applies similarly:
https://webpack.js.org/pluginsapi/compiler/
The Compiler exposes a run method which kickstarts all compilation work for 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.
Upvotes: 1