【问题标题】:Running 2 commands in npm script(nodemon && sass --watch)在 npm 脚本中运行 2 个命令(nodemon && sass --watch)
【发布时间】:2019-10-12 22:43:30
【问题描述】:

我有一个 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"
  },

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

"both": "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.js npm sass npm-scripts


    【解决方案1】:

    使用名为 concurrently 的包。

    npm install concurrently
    

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

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

    javascript - How can I run multiple npm scripts in parallel?

    【讨论】:

    • 我将您的回复标记为答案。它工作得很好。谢谢。
    猜你喜欢
    • 2017-05-10
    • 2016-11-11
    • 2020-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-17
    • 2021-09-01
    • 2019-11-30
    相关资源
    最近更新 更多