How can I run multiple npm scripts in parallel?

后端 未结 22 2109
灰色年华
灰色年华 2020-11-22 05:48

In my package.json I have these two scripts:

  \"scripts\": {
    \"start-watch\": \"nodemon run-babel index.js\",
    \"wp-server\": \"webpack-         


        
22条回答
  •  北海茫月
    2020-11-22 06:28

    I've checked almost all solutions from above and only with npm-run-all I was able to solve all problems. Main advantage over all other solution is an ability to run script with arguments.

    {
      "test:static-server": "cross-env NODE_ENV=test node server/testsServer.js",
      "test:jest": "cross-env NODE_ENV=test jest",
      "test": "run-p test:static-server \"test:jest -- {*}\" --",
      "test:coverage": "npm run test -- --coverage",
      "test:watch": "npm run test -- --watchAll",
    }
    

    Note run-p is shortcut for npm-run-all --parallel

    This allows me to run command with arguments like npm run test:watch -- Something.

    EDIT:

    There is one more useful option for npm-run-all:

     -r, --race   - - - - - - - Set the flag to kill all tasks when a task
                                finished with zero. This option is valid only
                                with 'parallel' option.
    

    Add -r to your npm-run-all script to kill all processes when one finished with code 0. This is especially useful when you run a HTTP server and another script that use the server.

      "test": "run-p -r test:static-server \"test:jest -- {*}\" --",
    

提交回复
热议问题