2

我有一个包含 html/css/javascript 文件的项目,我想输入命令npm start来运行json-serverlive-server

我试过这个命令:"start": "json-server --watch db.json && live-server",但它只启动第一个命令,而不是两个。

package.json

{
  "name": "testa-npm-live-server",
  "version": "1.0.0",
  "description": "",
  "main": "",
  "dependencies": {},
  "devDependencies": {
    "json-server": "^0.16.1",
    "live-server": "^1.2.1"
  },
  "scripts": {
    "start": "json-server --watch db.json && live-server"
  },
  "author": "",
  "license": "ISC"
}

IDE:vscode
节点版本:v12.18.1
NPM 版本:6.14.5

4

1 回答 1

3

使用concurrent 并行运行命令。&&以串行/顺序运行,即第二个命令仅在第一个命令完成运行后启动。

{
  "name": "testa-npm-live-server",
  "version": "1.0.0",
  "description": "",
  "main": "",
  "dependencies": {},
  "devDependencies": {
    "concurrently": "^5.2.0",
    "json-server": "^0.16.1",
    "live-server": "^1.2.1"
  },
  "scripts": {
    "start": "concurrently \"json-server --watch db.json\" \"live-server\""
  },
  "author": "",
  "license": "ISC"
}

非常感谢NodeSchool Campinas社区的帮助 :)

于 2020-07-02T22:21:18.790 回答