调用webpack CLI时,有没有办法知道构建成功还是失败?

When calling the webpack CLI, is there a way to know if the build has been successful or failed?

我有一个 deploy.sh 文件,它将调用 webpack,例如:

webpack --config webpack.prod.js

是否调用了 return 我可以用来 知道构建是否成功的东西? 因为我想知道我的 deploy.sh 脚本是否应该继续。

还有其他解决方案吗?

您可以使用 webpack CLI 脚本中的 exit code 来检测:

https://github.com/webpack/webpack-cli#exit-codes-and-their-meanings

build.sh

webpack --config webpack.prod.js

EXIT_CODE=$?

if [[ EXIT_CODE == "0" ]]; then
  echo "BUILD SUCCESSFUL"
  exit
else
  echo "ERROR ON BUILD SCRIPT"
  exit
fi