如何使用nodejs处理webpack-dev-server中的编译错误

时间:2017-10-18 07:39:53

标签: error-handling webpack webpack-dev-server

当我在webpack中使用nodejs时,它可以捕获每个编译错误,每次构建结束时都会调用观看回调。

const webpack = require("webpack");

const compiler = webpack({
  // Configuration Object
});

const watching = compiler.watch({
  /* watchOptions */
}, (err, stats) => {
  // Print watch/build result here...
  console.log(stats);
});

但是当我使用webpack-dev-server时,监听回调只在服务器启动时调用一次,在webpack-dev-server中使用nodejs时有什么方法可以捕获每个编译错误?

const compiler = Webpack(webpackConfig);
const server = new WebpackDevServer(compiler, {
  stats: {
    colors: true
  }
});

server.listen(8080, '127.0.0.1', () => {
  // only called once
  console.log('bla');
});

1 个答案:

答案 0 :(得分:1)

终于用插件解决了这个问题

,Call to a member function getClientOriginalName() on array

每次构建完成后都会调用此回调。