我寫blog很久以前
在我的構建流水線我有命令集版本
version "$(app.versionPrefix)$(Build.BuildNumber)"
$(app.versionPrefix) - 是一個前綴版本如0.1。
$(Build.BuildNumber) - 是建立版本
然後,我有環境文件
export const environment = {
apiUrl: 'https://....',
production: true,
version: '0.0.57'
}
那麼我js腳本來更新環境和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
}
版本
注意:您需要安裝插件替換文件中
然後在建管線我運行此腳本
node ./replace.build.js
在你的情況,如果你只需要瀏覽器,你可以調整腳本。
非常感謝您的先生。 – user2085143