Error handling 如何使用nodejs处理webpack dev服务器中的编译错误
当我在Error handling 如何使用nodejs处理webpack dev服务器中的编译错误,error-handling,webpack,webpack-dev-server,Error Handling,Webpack,Webpack Dev Server,当我在nodejs中使用webpack时,它可以捕获每个编译错误,监视回调将在每个构建结束时调用 const webpack = require("webpack"); const compiler = webpack({ // Configuration Object }); const watching = compiler.watch({ /* watchOptions */ }, (err, stats) => { // Print watch/build resu
nodejs
中使用webpack
时,它可以捕获每个编译错误,监视回调将在每个构建结束时调用
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
时,listen回调只在服务器启动时调用一次,在nodejs
中使用webpack-dev-server
时,是否有任何方法可以捕获每个编译错误
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');
});
最终用插件解决了这个问题
compiler.plugin('done',callback)
每次构建完成后,都会调用此回调。我相信webpack dev server config中的stats属性可能有助于您尝试执行的操作。看看这些选项。