如何实现一个插件

  • 调用插件 apply 函数传入 compiler 对象
  • 通过 compiler 对象监听事件

比如你想实现一个编译结束退出命令的插件

apply (compiler) {
  const afterEmit = (compilation, cb) => {
    cb()
    setTimeout(function () {
      process.exit(0)
    }, 1000)
  }

  compiler.plugin('after-emit', afterEmit)
}
}

module.exports = BuildEndPlugin

猜你喜欢

转载自blog.csdn.net/LuckXinXin/article/details/107855214