【发布时间】:2018-07-26 17:22:02
【问题描述】:
如何在构建期间访问环境变量的值以进行一些字符串替换。
例子:
aurelia_project/environments/dev.ts
export default {
debug: true,
testing: true,
pageBaseUrl: 'https://localhost:9000' // <-- This is the info I'd like to fetch
};
aurelia_project/environments/prod.ts
export default {
debug: true,
testing: true,
pageBaseUrl: 'https://www.foobar.com' // <-- This is the info I'd like to fetch
};
index.html
<!DOCTYPE html>
<html>
<head>
<!-- ... -->
<base href="{pageBasePath}">
<!-- ... -->
</head>
<!-- ... -->
</html>
aurelia_project/tasks/processIndex.ts
// ...
export default function processIndex() {
const pageBasePath = CLI.getEnvParamValue('pageBasePath');
return gulp.src('index.html')
.pipe(replace('{pageBasePath}', pageBasePath))
.pipe(gulp.dest(project.platform.outputIndex));
}
在processIndex.ts 中是否有一些与我虚构的CLI.getEnvParamValue('pageBasePath'); 等效的内置信息,还是我必须从aurelia_project/environments 中的适当文件中手动读取这些信息(使用CLIOptions.getEnvironment())?
【问题讨论】:
标签: environment-variables aurelia