How to suppress output when running npm scripts

后端 未结 5 501
日久生厌
日久生厌 2020-12-23 10:48

I have decided to experiment with npm scripts as a build tool and so far I like it. One issue I\'d like to solve is when running a script to run jshint when something doesn

5条回答
  •  佛祖请我去吃肉
    2020-12-23 11:44

    All scripts:

    You can fix this by suppressing the output of npm overall, by setting the log level to silent in a couple ways:

    On each npm run invocation:

    npm run --silent 
    

    Or globally by creating a .npmrc file(this file can be either in your project directory or your home folder) with the following:

    loglevel=silent
    

    Resources:

    npm log level config: https://docs.npmjs.com/misc/config#loglevel

    npmrc: https://docs.npmjs.com/misc/config#loglevel

    Each script, individually:

    A simple trick I've used to get around this issue on certain scripts like linting is to append || true at the end of such scripts. This will work without any npm config changes.

    This will ensure that the script will always exit with a 0 status. This tricks npm into thinking the script succeed, hence hiding the ERR messages. If you want to be more explicit, you can append || exit 0 instead and it should achieve the same result.

    {
      "scripts": {
        "lint": "jshint || true",
       }
    }
    

提交回复
热议问题