Angular4自动发布带有versionNumber的新代码

时间:2018-09-26 13:30:14

标签: angular deployment release

我正在使用angular4。我想知道是否有一种方法可以在每次我部署代码时自动添加一个新的发行版号。

有人对此有经验吗?

非常感谢

1 个答案:

答案 0 :(得分:1)

您的角度应用名称和版本存储在package.json中,您可以创建一个npm脚本命令来像这样运行

npm run command-name

这是我的设置package.json

{
  "name": "test-app",
  "version": "0.0.3",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "build-patch": "ng build && npm version patch",
    "build-minor ": "ng build && npm version minor",
    "build-major": "ng build && npm version major",
    "build": "ng build"
  },
...
}

运行和更新补丁号

npm run build-patch

这将运行ng build并将软件包版本更新为0.0.3,因为它是0.0.3

这是在终端中运行命令的输出

C:\test-app>npm run build-patch

> test-app@0.0.3 build-patch C:\test-app
> ng build && npm version patch


Date: 2018-09-26T15:28:56.189Z
Hash: 3f1b223e30325514ebd1
Time: 6742ms
chunk {main} main.js, main.js.map (main) 9.42 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 227 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.22 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 15.6 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 2.95 MB [initial] [rendered]
v0.0.4