我在[[package.json中有这三个命令”{
"build-major": "npm version major --no-git-tag-version && node ./replace.build.js && node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod --base-href /QMobile/",
"build-minor": "npm version minor --no-git-tag-version && node ./replace.build.js && node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod --base-href /QMobile/",
"build-patch": "npm version patch --no-git-tag-version && node ./replace.build.js && node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod --base-href /QMobile/",
}
我的replace.build.js包含以下代码:
var replace = require('replace-in-file');
var package = require("./package.json");
var buildVersion = package.version;
const options = {
files: 'src/environments/environment.prod.ts',
from: /version: '(.*)'/g,
to: "version: '"+ buildVersion + "'",
allowEmptyPaths: false,
};
const htmlOptions={
files:'src/index.html',
from: /<meta name="version" content="(.*)">/g,
to: '<meta name="version" content="'+buildVersion+'">',
allowEmptyPaths: false
}
try {
let changedFiles = replace.sync(options);
if (changedFiles == 0) {
throw "Please make sure that file '" + options.files + "' has \"version: ''\"";
}
let indexFileChanged = replace.sync(htmlOptions);
if (indexFileChanged == 0) {
throw "Index.html Version Change Failed";
}
console.log('Build version set: ' + buildVersion);
}
catch (error) {
console.error('Error occurred:', error);
throw error
}
因此,每次进行Angular Build时,我都会更改3个文件?
index.html,environment.prod.ts和package.json
[我正在寻找一种解决方案,以使构建过程中也将这些更改也推送到当前分支,或者采用一种标准方法来保持内部版本号与所有分支同步。
我的package.json {中有这三个命令{“ build-major”:“ npm version major --no-git-tag-version && node ./replace.build.js && node --max_old_space_size = 8192 node_modules / @ ...
我正在寻找一种解决方案,以使这些更改被推到 当前分支也在构建过程或标准方式下进行 保持内部版本号与所有分支同步。