concurrently
concurrently 同时执行多个script
当多个nodejs项目需要同时启动npm script的时候,可以将多个script运行在同一个shell窗口内,而且可以统一管理打印信息,更好的管理多个node的项目
安装
npm i -D concurrently
yarn add --dev concurrently
script使用
package.json
语法:
"start": "concurrently \"command1 arg\" \"command2 arg\""
示例1
"scripts": {
"dev": "concurrently -n=S1,S2 -c=green,yellow \"npm run script1\" \"npm run script2\"",
"script1": "node xxxx",
"script2": "node xxxx",
}
直接调用
语法:
concurrently "command1 arg" "command2 arg"
部分常用参数:
--kill-others
/-k
关闭某些运行中的进程 "name1" "name2"
-c
/--color
设置对应shell窗口颜色
-n
/--name
设置对应shell在log内显示的名字
-r
/--raw
查看对应命令执行的
js
源文件
导入使用
语法: concurrently(commands[, options])
commands
options
const concurrently = require('concurrently');
concurrently([
'npm:watch-*',
{ command: 'nodemon', name: 'server' },
{ command: 'deploy', name: 'deploy', env: { PUBLIC_KEY: '...' } },
{ command: 'watch', name: 'watch', cwd: path.resolve(__dirname, 'scripts/watchers')}
], {
prefix: 'name',
killOthers: ['failure', 'success'],
restartTries: 3,
cwd: path.resolve(__dirname, 'scripts'),
}).then(success, failure);