使用命令行参数设置环境变量
问题描述:
是否可以使用命令行参数传递环境变量的值?使用命令行参数设置环境变量
E.g.我想设置这是由我的生成服务器生成的版本号:
aurelia_project /环境/ prod.ts
export default {
debug: false,
testing: false,
// $buildVersion$ should be replaced during build with the actual value
buildVersion: $buildVersion$
};
虚命令:au build --env prod --buildVersion 1.1.1
编辑
由于目前似乎不可能,因此我在Aurelias上创建了功能请求
答
由于proposed by AStoker我能解决这个问题的方式如下:
aurelia_project /环境/ prod.ts
export default {
debug: false,
testing: false,
buildVersion: {buildVersion} // <-- Will be replace during build
};
aurelia_project/transpile.js
// ...
import * as replace from 'gulp-replace';
function configureEnvironment() {
let env = CLIOptions.getEnvironment();
let buildVersion = CLIOptions.getFlagValue('buildVersion') || '0.0.0';
return gulp.src(`aurelia_project/environments/${env}.ts`)
.pipe(changedInPlace({firstPass: true}))
.pipe(replace('{buildVersion}', buildVersion)) // <-- Replacement happens here
.pipe(rename('environment.ts'))
.pipe(gulp.dest(project.paths.root));
}
// ...
命令行调用:au build --buildVersion 1.1.1