使用Webpack运行构建过程,我得到了一些警告。我认为这是一些警告错误,对于IMO,它应该停止构建过程。
> yarn build:staging
yarn run v1.10.1
$ webpack --env.staging --env.NODE_ENV=staging
Version: webpack 4.23.1
[...]
[795] ./src/index.css 1.05 KiB {0} [built]
+ 793 hidden modules
WARNING in ./src/assets/banner/3.jpg
Module build failed (from ./node_modules/image-webpack-loader/index.js):
Error: Command failed: /home/circleci/repo/node_modules/mozjpeg/vendor/cjpeg
/home/circleci/repo/node_modules/mozjpeg/vendor/cjpeg: error while loading shared libraries: libpng16.so.16: cannot open shared object file: No such file or directory
at Promise.all.then.arr (/home/circleci/repo/node_modules/imagemin-mozjpeg/node_modules/execa/index.js:236:11)
at process._tickCallback (internal/process/next_tick.js:68:7)
@ ./src/assets/banner sync ^\.\/.*\.jpg$ ./3.jpg
@ ./src/scenes/home/index.js
@ ./src/router.js
@ ./src/index.js
@ multi babel-polyfill ./src/index.js
[...]
Done in 26.03s.
此“警告”应停止整个过程并退出。 有没有办法告诉webpack以纱线作为驱动程序,以停止某种警告(并返回错误代码)??我的CI流程认为一切都很好,这不是我所期望的行为
答案 0 :(得分:1)
您可以从其errors
对象的Webpack实例中访问warnings
和stats
,然后选择拒绝/退出该过程:https://github.com/webpack/docs/wiki/node.js-api
例如:
if(stats.errors.length > 0 || process.warning.length > 0) {
process.exit;
}
如果要在第一次错误抛出时退出,可以在配置中设置bail
选项:https://webpack.js.org/configuration/other-options/#bail