class MyPlugin {
apply(compiler) {
compiler.hooks.done.tap('My Plugin', (stats) => {
console.log('Hello World!');
});
}
}
module.exports = MyPlugin;
plugins: [new MyPlugin()]
module.exports = class MyPlugin {
constructor(options) {
this.options = options;
}
apply() {
console.log('apply', this.options);
}
};
参数校验阶段可以直接 throw 的方式抛出
throw new Error('Error Message')
通过 compilation 对象的 warnings 和 errors 接收
compilation.warnings.push('warning')
compilation.errors.push('errors')
通过 compilation 进行文件写入.