How can I run multiple npm scripts in parallel?

后端 未结 22 2489
灰色年华
灰色年华 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:24

    Simple node script to get you going without too much hassle. Using readline to combine outputs so the lines don't get mangled.

    const { spawn } = require('child_process');
    const readline = require('readline');
    
    [
      spawn('npm', ['run', 'start-watch']),
      spawn('npm', ['run', 'wp-server'])
    ].forEach(child => {
        readline.createInterface({
            input: child.stdout
        }).on('line', console.log);
    
        readline.createInterface({
            input: child.stderr,
        }).on('line', console.log);
    });
    

提交回复
热议问题