在节点包文件中运行多个命令?

时间:2014-05-16 01:22:15

标签: node.js

例如:

"scripts": {
    "watch": "coffee --watch --compile .; compass watch public/compass"
}, 

我怎样才能使这个工作,所以它编译我的coffescripts和我的指南针项目?

2 个答案:

答案 0 :(得分:18)

http://substack.net/task_automation_with_npm_run

顺序子任务

如果你想要连续运行2个任务,你可以只运行由&&amp ;:

分隔的每个任务
"build": "npm run build-js && npm run build-css"

并行子任务

如果您想并行运行某些任务,只需使用&作为分隔符!

"watch": "npm run watch-js & npm run watch-css"

答案 1 :(得分:2)

安装parallelshell npm pacakge

npm install parallelshell --save-dev

在你的npm脚本中使用它代替&

"build": "echo TODO: build the project and start watching",
"serve": "echo TODO: start a development web server",
"start": "parallelshell \"npm start build\" \"npm start serve\""

并行运行多个子任务(Mac,Linux,Windows)

$ npm start

---或者---

创建一个.js文件,通过Node.js child_process旋转多个进程。这是一个例子:

"start": "node tools/start.js"

tools/start.js可能如下所示:

https://github.com/kriasoft/aspnet-starter-kit/blob/master/tools/start.js