node.jsbashwebpackbuildwebpack-cli

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


I have a deploy.sh file that will call webpack like:

webpack --config webpack.prod.js

Does that call return something that I can use to know if the build has been successful or not? Because I'd like to know if my deploy.sh script should continue or not.

Any other solutions to this?


Solution

  • You can use the exit code from the webpack CLI script to detect this:

    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