Skip to content

Improvement: externalizing environment from Angular CLI build process #2495

@bjornharvold

Description

@bjornharvold

There is a great article: http://www.jvandemo.com/how-to-configure-your-angularjs-application-using-environment-variables/ about externalizing the environment file from the build. The deployment phase can be responsible for providing the app with the correct environment variables. "Build once - Deploy anywhere".

What I did in my own project to get this to work was to externalize my environment parameters the same way as the article had it. Then I imported those variables in the environment.dev.ts file like so:

export const environment = {
production: false,
environment: window['__env'].environment,
build: window['__env'].build,
siteName: window['__env'].siteName,
};

I also referred to my real environment file in index.html via a javascript import.

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[ x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
No bug

Expected behavior
No bug

Minimal reproduction of the problem with instructions
Environment files are compiled with the app during build phase for Angular CLI. It should [ideally] be outside.

What is the motivation / use case for changing the behavior?
Build once - Deploy anywhere.

  • Angular version: 2.0.1
  • Language: [TypeScript 2.0.2]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions