npm scripts 常用规范总结

npm scripts 常用规范总结

随着 npm scripts 使用越来越多,需要规范一下, npm run 的使用词。

定义

我定义如下形式:

npm run <action>:<scope>:<target>

action: 是指行为动作,一般用动词表示,用来表示自己的意图,意思就是我想干什么

scope: 是指在当前 action 下的范围,一般是名词,用来约束 action 的范围,意思是某某环境下,我干什么

target: 是指具体的目标,你想达成的目标,这个可是名词,这种情况下就非常直接。

例子

这可能说的有点抽象,下面来举个几个例子说明下:

npm run start
npm run start:dev

这两个命令可以看出来,是干什么的吧,一个是生产运行,一个是开发运行

npm run build
npm run build:html

这是打包文件的命令

npm run lint && npm run test && npm run build && npm run publish

这是顺序执行命令

npm run lint:fe:js & npm run lint:fe:css

这是并行执行命令

说明

  1. 需要说明如果 命令太多了,建议新建一个文件夹 scripts 进行命令的编写。
  2. 一般生产环境不用标明
  3. 可以使用 npm-run-all 工作量的简化

补充建议词

这里列出了常用的一些词进行参考:

action

  • lint
  • watch
  • clean
  • build
  • start
  • test
  • publish

scope

  • dev
  • js
  • html

target

  • index
  • gulp
  • jake
原文地址:https://www.cnblogs.com/htoooth/p/8981497.html