很久以前我写了一篇博客
在我的构建流程中,我有一个命令来设置版本号。
version "$(app.versionPrefix)$(Build.BuildNumber)"
$(app.versionPrefix) - 是前缀版本,例如0.1。
$(Build.BuildNumber) - 是构建版本。
然后我有环境文件。
export const environment = {
apiUrl: 'https://....',
production: true,
version: '0.0.57'
}
然后我有一个JavaScript脚本来更新环境和config.xml中的版本号。
var replace = require('replace-in-file');
var package = require("./package.json");
var buildVersion = package.version;
const options = {
files: ['config.xml'],
from: /" version="([0-9]*.[0-9]*.[0-9]*)"/g,
to: "\" version=\""+ buildVersion + "\"",
allowEmptyPaths: false,
};
const optionsEnv = {
files: ['src/environments/environment.prod.ts'],
from: /version: '(.*)'/g,
to: "version: '"+ buildVersion + "' ",
allowEmptyPaths: false,
};
try {
let changedFiles = replace.sync(options);
if (changedFiles == 0) {
throw "Please make sure that file '" + options.files + "' has \"version: ''\"";
}
changedFiles = replace.sync(optionsEnv);
if (changedFiles == 0) {
throw "Please make sure that file '" + optionsEnv.files + "' has \"version: ''\"";
}
console.log('Build version set: "' + options.to + '"');
}
catch (error) {
console.error('Error occurred:', error);
throw error
}
注意:你需要安装插件replace-in-file
然后在构建管道中运行以下脚本:
node ./replace.build.js
在您的情况下,如果只需要浏览器,则可以调整脚本。