叉烧店并不卖叉烧

npm中package.json的scripts域

npm TTT 56℃ 0评论

参考

怎么使用

有如下package.json文件:

{
  "name": "basic",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {},
  "devDependencies": {
    "webpack": "^4.17.1",
    "webpack-cli": "^3.1.0"
  }
}

如果要运行scripts中的test,只需要在package.json文件所在目录的命令行中输入npm test就可以运行了。

其中,scripts域中的值都是当前命令行处理器的脚本语言。是可以直接运行的

有哪些值

npm supports the "scripts" property of the package.json file, for the following scripts:

  • prepublish: Run BEFORE the package is packed and published, as well as on localnpm install without any arguments. (See below)
  • prepare: Run both BEFORE the package is packed and published, and on localnpm install without any arguments (See below). This is run AFTERprepublish, but BEFOREprepublishOnly.
  • prepublishOnly: Run BEFORE the package is prepared and packed, ONLY onnpm publish. (See below.)
  • prepack: run BEFORE a tarball is packed (onnpm pack,npm publish, and when installing git dependencies)
  • postpack: Run AFTER the tarball has been generated and moved to its final destination.
  • publish, postpublish: Run AFTER the package is published.
  • preinstall: Run BEFORE the package is installed
  • install, postinstall: Run AFTER the package is installed.
  • preuninstall, uninstall: Run BEFORE the package is uninstalled.
  • postuninstall: Run AFTER the package is uninstalled.
  • preversion: Run BEFORE bumping the package version.
  • version: Run AFTER bumping the package version, but BEFORE commit.
  • postversion: Run AFTER bumping the package version, and AFTER commit.
  • pretest, test, posttest: Run by thenpm test command.
  • prestop, stop, poststop: Run by thenpm stop command.
  • prestart, start, poststart: Run by thenpm start command.
  • prerestart, restart, postrestart: Run by thenpm restart command. Note:npm restart will run the stop and start scripts if norestart script is provided.
  • preshrinkwrap, shrinkwrap, postshrinkwrap: Run by thenpm shrinkwrap command.

以上是package.json文件中scripts域中的不同特性,其中每个特性名称后面都给出了对应特性的运行条件。比如果我们要运行scripts域的test特性,它后面给出直接运行以下命令即可npm test

运行任意的scripts

另外,可以执行 npm run-script <stage>来执行任意的scripts。对于匹配名字的pre和post命令也是一样(比如,premyscript,myscript,postmyscript)。依赖中的脚本能通过npm explore <pkg> -- npm run <stage>来运行。

转载请注明:叉烧店 » npm中package.json的scripts域

喜欢 (0)
发表我的评论
取消评论

CAPTCHA Image
Reload Image
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址