1.package.json配置
{
"name": "myproject2",
"version": "1.5.4",
"description": "",
"main": "dist/app.js",
"scripts": {
"precommit": "node -v",
"dev": "wepy build --watch",
"qa": "NODE_ENV=qa wepy build --no-cache",
"build": "cross-env NODE_ENV=production V=$v S=$s wepy build --no-cache",
"test": "echo \"Error: no test specified\" && exit 1",
"version": "V=$v node version.js"
}
}
运行时:
(s=3 v=1.5.1 npm run build)
s为接口版本参数 v为版本号
运行时进行接口版本替换 使用replace插件替换版本
// 判定现在的环境
const env = process.env.NODE_ENV === 'production' ? 'prod' : 'dev'
// 版本号
const version = __VERSION__ || '开发环境'
// 多环境接口 url
const baseUrl = {
// dev: 'https://exam.zmgongzuoshi.top/api/v1',
prod: 'https://exam.sunlands.site/api/s__SVERSION__',
dev: 'https://exam.sunlands.site/api/s1'
}
2.version.js(npm run version)
读取文件 写入文件 将package.json中的version动态修改
const fs = require('fs')
const version = process.env.V
fs.readFile('./package.json', (err, data) => {
if (err) throw new Error(err)
data = JSON.parse(data.toString())
data.version = version
data = JSON.stringify(data, null, 2)
fs.writeFileSync('./package.json', data)
return true
})
3.change log(npm run changelog)
conventional-changelog 就是生成 Change log
$ npm install -g conventional-changelog
配置package.json
{
"scripts": {
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -w -r 0"
}
}