为什么我可以在 package.json 中添加脚本到脚本?

Why can I add script to script in package.json?

我正在尝试将脚本添加到 package.json 文件中的脚本监视中。 例如,我得到:

{
"scripts": {
    "delete": "rm -f wwwroot/*.js wwwroot/*.css wwwroot/*.html wwwroot/*.map"
    "watch": "npm run delete; parcel watch Client/index.html --out-dir wwwroot"
  }
}

然后当我 运行 npm run watch,在终端中,它抛出这个错误:


> projectName@1.0.0 watch C:\Users\username\userProjectName\path\ProjectName
> npm run delete; parcel watch Client/index.html --out-dir wwwroot

npm ERR! missing script: delete;
npm ERR!
npm ERR! Did you mean this?
npm ERR!     delete

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\username\AppData\Roaming\npm-cache\_logs19-05-01T17_17_44_173Z-debug.lognpm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! projectName@1.0.0 watch: `npm run delete; parcel watch Client/index.html --out-dir wwwroot`
npm ERR! Exit status 1npm ERR!
npm ERR! Failed at the projectName@1.0.0 watch script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\username\AppData\Roaming\npm-cache\_logs19-05-01T17_17_44_193Z-debug.log

但是当我手动 运行 它时,我的意思是实际去终端并输入:npm run delete; parcel watch Client/index.html --out-dir wwwroot,它 运行 完美

您只是在 delete 脚本后少了一个逗号。

{
"scripts": {
    "delete": "rm -f wwwroot/*.js wwwroot/*.css wwwroot/*.html wwwroot/*.map",
    "watch": "npm run delete; parcel watch Client/index.html --out-dir wwwroot"
  }
}