构建Angular 2应用程序时访问系统变量(环境变量)



我需要使用一个系统变量构建我的角度应用程序。

系统变量

server_url = http://google.com

我的环境.ts文件看起来像

export const environment = {
  production: false,
  serveUrl: 'http://someurl.com',
  mleServerUrl: 'http://someurl2.com',
  botServerUrl: 'http://someurl2.com',
  DEBUG_LOG: true,
  azureAD: true,
  mleEnvironment: 'dev',
  multtenant: true,
  e2eTest: false
};

执行ng build命令。

您需要一个环境。

export const environment = {
  production: true,
  serveUrl: 'http://google.com',
};

然后您必须执行ng build --prod

请参阅https://github.com/angular/angular-cli/wiki/build/build

如果要使用系统环境变量而不是标准角度方法,这里有几个选项:

  1. 创建可通过Angular应用程序可用的ENV服务;利用env.js文件可以在部署时间进行修改。https://www.jvandemo.com/how-to-use-environment-variobles-to-configure-your-angular-angular-application-without-a-rebuild/

  2. 使用自定义的角构建修改您的WebPack进程,该过程允许您在构建时间读取系统环境变量>

最新更新