首页 > 解决方案 > 在 npm 脚本中运行 2 个命令(nodemon && sass --watch)

问题描述

我有一个 package.json 文件,看起来像这样。


"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node src/app.js",
    "dev": "nodemon src/app.js -e js,hbs ",
    "scss": "sass --watch public/scss:public/css",
    "both": "nodemon src/app.js -e js,hbs && sass --watch public/scss:public/css",
    "both2" : "npm run dev && npm run scss"
  },

我想知道为什么我不能运行这两个命令:

“两者”:“nodemon src/app.js -e js,hbs && sass --watch public/scss:public/css”

经过

npm run both

当我尝试运行它时,只有第一个命令有效。

Github 存储库在下面,以防万一您需要一些测试。

https://github.com/tuanphanfi/weather-app-nodejs/

标签: node.jsnpmsassnpm-scripts

解决方案


使用一个名为concurrent的包。

npm install concurrently

然后你可以制作一个名为both

"both": "concurrently \"nodemon src/app.js -e js,hbs\" \"sass --watch public/scss:public/css\""

请参阅javascript - 如何并行运行多个 npm 脚本?


推荐阅读