Search code examples
angularenvironment

Angular Environment file not seen in the distribution folder


I have an angular 8 application and testing the timeout set in the enviornment.ts file. I have currently set the timeout to 6 minutes I have two enviornment files that is enviornment.ts and enviornment.prod.ts. I believe that enviornment.prod.ts is used when the ng build --prod is executed.

After running the ng build command , I am unable to locate the enviornment file in the distribution folder.Could somebody tell me where can i find it. Is it in some binary etc

This is what my environment file looks like

// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.

export const environment = {
    production: false,
    baseUrl: "http://localhost:57973",
    loginUrl: "/Login",
    adminUrl: "/Admin",
    userIdleMinutes: 10
};

Solution

  • First, you need to actually use your environment.ts file in your code. For example:

    import { Component } from '@angular/core';
    
    import { environment } from '../environments/environment';
    
    @Component({})
    export class AppComponent {
      env = environment;
      constructor() {
        console.log(this.env.baseUrl);
      }
    }
    

    Otherwise, unused code will be tree-shaked.

    Then, your code from the environment.ts file will be bundled to the main-XXXXX.js file.