Home > Mobile >  Can we remove environment.ts file from Angular project?
Can we remove environment.ts file from Angular project?

Time:01-25

I have environment.ts and environment.prod.ts file in my angular web project.

I know that environment.ts is the default configuration for any project. I want to rename it to environment.dev.ts, but I m facing a lot of errors.

After research, i found that in Angular v6, we do something like:

 "fileReplacements": [
     {
       "replace": "src/environments/environment.ts",
       "with": "src/environments/environment.prod.ts"
     }

after seeing this, I think environment.ts file is compulsory and I should create a new file environment.dev.ts file and just replace it.

Can anyone tell the feasibility of the both the approaches ?

CodePudding user response:

Usually, environment.ts contains DEV configuration so there is no need to replace it. But, if the need arises, you can extend DEV build config in angular.json with file repacement for DEV build. Same for any other type of build specified in angular.json.

"configurations": {
  "dev": {
    ...
    "fileReplacements": [{
      "replace": "src/environments/environment.ts",
      "with": "src/environments/environment.dev.ts"
    }]
  }
},

CodePudding user response:

I recommend that you leave the environment.ts and create a new configuration for the dev, so that when you call the development configuration, it takes the correct environment.

 "dev": {
         "fileReplacements": [{
                                "replace": "src/environments/environment.ts",
                                "with": "src/environments/environment.dev.ts".
             }]
         }
  •  Tags:  
  • Related