【问题标题】:How to run few npm scripts in one-line shell command?如何在一行 shell 命令中运行几个 npm 脚本?
【发布时间】:2019-11-30 15:56:53
【问题描述】:

我在package.json中有三个脚本:

  1. 观察服务器 TypeScript
  2. Nodemon
  3. 网页包
    "scripts": {
        "watch-server": "tsc --watch --project ./server/tsconfig.json",
        "watch-node": "nodemon --watch ./server/build/ --watch ./server/templates -e js,json,pug",
        "watch-client": "webpack --config ./webpack/webpack.dev.conf.js --watch"
      }

每次我启动计算机并打开 VS Code 时,我都需要打开三个单独的 PowerShell 终端并一一输入这些命令。有没有办法在一个 shell 命令中使用自己的命令启动这三个独立的终端?也许通过tasks.json?

【问题讨论】:

    标签: node.js visual-studio-code


    【解决方案1】:

    在 linux 或任何 bash 终端上,您可以使用 && 组合多个命令,i 你可以这样做

    npm run watch-server && npm run watch-node && npm run watch-client
    

    建议使用分号在 Google 上快速搜索 powershell 所以在 powershell 上,如果使用 && 不起作用,您可以执行以下操作

    npm run watch-server;npm run watch-node ; npm run watch-client
    

    另外请记住,您还可以在 package.json 中的 npm 脚本中添加第四个命令,您可以在其中使用适合您的这些组合命令之一,例如

    start-all: npm run watch-server && npm run watch-node && npm run watch-client
    

    然后运行

    npm run start-all
    

    【讨论】:

    • 我做了"watch-all": "npm run watch-server && npm run watch-node && npm run watch-client"。这只会在第一个 && 之前运行第一个命令。使用分号它不起作用 :(
    • @JamesJGoodwin 这个链接可能会有所帮助superuser.com/questions/612409/…
    猜你喜欢
    • 2014-09-22
    • 2019-06-07
    • 1970-01-01
    • 2017-08-16
    • 2019-09-02
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    相关资源
    最近更新 更多