webpack plugins - ythy/blog GitHub Wiki
this的指向问题:
CleanPathPlugin.prototype.apply = function(compiler) {此函数里this不指向全局,需要转换。this.mPath.forEach((elem)=>{这里thisarrow函数指向CleanPathPlugin, 函数调用需要通过call()来进行
function CleanPathPlugin( path, option ){
this.options = option || {};
this.mPath = path;
}
function cleanHandle(){
if(this.mPath && this.mPath.length > 0){
this.mPath.forEach((elem)=>{
removedFolder.call(this, elem);
});
}
}
CleanPathPlugin.prototype.apply = function(compiler) {
var _this = this;
compiler.plugin("compile", function() {
if(!debug)
cleanHandle.call(_this);
});
};
module.exports = CleanPathPlugin;