简体   繁体   English

如何在单行shell命令中运行几个npm脚本?

[英]How to run few npm scripts in one-line shell command?

I have three scripts in package.json : 我在package.json有三个脚本:

  1. Watch server TypeScript 监视服务器TypeScript
  2. Nodemon Nodemon
  3. Webpack 的WebPack
    "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"
      }

Everytime I start my computer and open VS Code I need to open three separate PowerShell terminals and type in those commands one-by-one. 每次启动计算机并打开VS Code时,我需要打开三个单独的PowerShell终端,然后逐一键入这些命令。 Is there any way to launch these three separate terminals with their own commands in one shell command? 有什么方法可以在一个shell命令中使用它们自己的命令来启动这三个单独的终端? Maybe via tasks.json ? 也许通过tasks.json

On linux or any bash terminal, you can use && to combine multiple commands, i You can do as 在linux或任何bash终端上,您可以使用&&组合多个命令。

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

A quick google search for powershell suggested using semicolon so on powershell you can do something like below if using && does not work 建议您使用分号对Google的Powershell进行快速的Google搜索,以便在Powershell上执行以下操作(如果使用&&不起作用)

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

Also keep in mind, you can additionally add fourth command in your npm scripts in package.json where you can use one of these combined commands which works for you, like 另外请记住,您还可以在package.json的npm脚本中添加第四个命令,在其中可以使用适合您的以下组合命令之一,例如

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

and then run 然后运行

npm run start-all

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM