Repository: jhipster/jhipster-lite
Pull request #11981 (2025-02-24 20:20:40)

Angular: Configure environment-specific defaults
Related to https://angular.dev/tools/cli/environments#configure-environment-specific-defaults

![image](https://github.com/user-attachments/assets/435e394c-70a3-4bcb-b4be-1fb862b5b065)



Patch:
diff --git a/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactory.java
index d2b5de69f..eaf57b65a 100644
--- a/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactory.java
+++ b/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactory.java
@@ -114,8 +114,8 @@ public class AngularModuleFactory {
           .addFile("AngularLogo.svg")
           .and()
         .batch(SOURCE.file("src/main/webapp/environments"), to("src/main/webapp/environments"))
-          .addTemplate("environment.prod.ts")
-          .addTemplate("environment.prod.spec.ts")
+          .addTemplate("environment.local.ts")
+          .addTemplate("environment.local.spec.ts")
           .addTemplate("environment.ts")
           .addTemplate("environment.spec.ts")
           .and()
diff --git a/src/main/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2ModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2ModuleFactory.java
index 0576df51b..8d699485b 100644
--- a/src/main/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2ModuleFactory.java
+++ b/src/main/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2ModuleFactory.java
@@ -119,7 +119,7 @@ public class AngularOauth2ModuleFactory {
         .in(path("src/main/webapp/environments/environment.ts"))
           .add(ENVIRONMENT_NEEDLE, keycloakEnvironment(indentation))
           .and()
-        .in(path("src/main/webapp/environments/environment.prod.ts"))
+        .in(path("src/main/webapp/environments/environment.local.ts"))
           .add(ENVIRONMENT_NEEDLE, keycloakEnvironment(indentation))
           .and()
         .in(path("angular.json"))
diff --git a/src/main/resources/generator/client/angular/core/angular.json.mustache b/src/main/resources/generator/client/angular/core/angular.json.mustache
index 9bbaad998..b84a8c82e 100644
--- a/src/main/resources/generator/client/angular/core/angular.json.mustache
+++ b/src/main/resources/generator/client/angular/core/angular.json.mustache
@@ -46,19 +46,19 @@
                   "maximumError": "4kb"
                 }
               ],
-              "fileReplacements": [
-                {
-                  "replace": "src/main/webapp/environments/environment.ts",
-                  "with": "src/main/webapp/environments/environment.prod.ts"
-                }
-              ],
               "outputHashing": "all"
             },
             "development": {
               "optimization": false,
               "extractLicenses": false,
               "sourceMap": true,
-              "namedChunks": true
+              "namedChunks": true,
+              "fileReplacements": [
+                {
+                  "replace": "src/main/webapp/environments/environment.ts",
+                  "with": "src/main/webapp/environments/environment.local.ts"
+                }
+              ]
             }
           },
           "defaultConfiguration": "production"
diff --git a/src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.local.spec.ts.mustache b/src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.local.spec.ts.mustache
new file mode 100644
index 000000000..687fb0600
--- /dev/null
+++ b/src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.local.spec.ts.mustache
@@ -0,0 +1,7 @@
+import { environment } from './environment.local';
+
+describe('Environment Configuration (development)', () => {
+  it('should have production mode disabled', () => {
+    expect(environment.production).toBeFalsy();
+  });
+});
diff --git a/src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.prod.ts.mustache b/src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.local.ts.mustache
similarity index 60%
rename from src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.prod.ts.mustache
rename to src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.local.ts.mustache
index c9669790b..a20cfe557 100644
--- a/src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.prod.ts.mustache
+++ b/src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.local.ts.mustache
@@ -1,3 +1,3 @@
 export const environment = {
-  production: true,
+  production: false,
 };
diff --git a/src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.prod.spec.ts.mustache b/src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.prod.spec.ts.mustache
deleted file mode 100644
index 96fb6eff9..000000000
--- a/src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.prod.spec.ts.mustache
+++ /dev/null
@@ -1,7 +0,0 @@
-import { environment } from './environment.prod';
-
-describe('Environment Configuration (prod)', () => {
-  it('should have production mode enabled', () => {
-    expect(environment.production).toBeTruthy();
-  });
-});
diff --git a/src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.spec.ts.mustache b/src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.spec.ts.mustache
index 24f483cca..e095a3c37 100644
--- a/src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.spec.ts.mustache
+++ b/src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.spec.ts.mustache
@@ -1,7 +1,7 @@
 import { environment } from './environment';
 
 describe('Environment Configuration', () => {
-  it('should have production mode disabled', () => {
-    expect(environment.production).toBeFalsy();
+  it('should have production mode enabled', () => {
+    expect(environment.production).toBeTruthy();
   });
 });
diff --git a/src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.ts.mustache b/src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.ts.mustache
index a20cfe557..c9669790b 100644
--- a/src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.ts.mustache
+++ b/src/main/resources/generator/client/angular/core/src/main/webapp/environments/environment.ts.mustache
@@ -1,3 +1,3 @@
 export const environment = {
-  production: false,
+  production: true,
 };


Test patch:
diff --git a/src/test/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactoryTest.java
index e8f79fed5..4fab93ffa 100644
--- a/src/test/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactoryTest.java
+++ b/src/test/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactoryTest.java
@@ -114,8 +114,8 @@ class AngularModuleFactoryTest {
       .hasPrefixedFiles(
         "src/main/webapp/environments",
         "environment.ts",
-        "environment.prod.ts",
-        "environment.prod.spec.ts",
+        "environment.local.ts",
+        "environment.local.spec.ts",
         "environment.spec.ts"
       )
       .hasPrefixedFiles("src/main/webapp", "index.html", "main.ts", "styles.css");
diff --git a/src/test/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2ModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2ModuleFactoryTest.java
index 95cb398a6..bf947bf08 100644
--- a/src/test/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2ModuleFactoryTest.java
+++ b/src/test/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2ModuleFactoryTest.java
@@ -66,7 +66,7 @@ class AngularOauth2ModuleFactoryTest {
         """
       )
       .and()
-      .hasFile("src/main/webapp/environments/environment.prod.ts")
+      .hasFile("src/main/webapp/environments/environment.local.ts")
       .containing(
         """
           keycloak: {
@@ -85,11 +85,11 @@ class AngularOauth2ModuleFactoryTest {
   }
 
   private static ModuleFile environmentFile() {
-    return file("src/test/resources/projects/angular/environment.ts", "src/main/webapp/environments/environment.ts");
+    return file("src/test/resources/projects/angular/environment.local.ts", "src/main/webapp/environments/environment.local.ts");
   }
 
   private static ModuleFile prodEnvironmentFile() {
-    return file("src/test/resources/projects/angular/environment.prod.ts", "src/main/webapp/environments/environment.prod.ts");
+    return file("src/test/resources/projects/angular/environment.ts", "src/main/webapp/environments/environment.ts");
   }
 
   private static ModuleFile angularJsonFile() {
diff --git a/src/test/resources/projects/angular/angular.json b/src/test/resources/projects/angular/angular.json
index a5845d8f8..ca8ae178a 100644
--- a/src/test/resources/projects/angular/angular.json
+++ b/src/test/resources/projects/angular/angular.json
@@ -52,7 +52,7 @@
               "fileReplacements": [
                 {
                   "replace": "src/main/webapp/environments/environment.ts",
-                  "with": "src/main/webapp/environments/environment.prod.ts"
+                  "with": "src/main/webapp/environments/environment.local.ts"
                 }
               ],
               "outputHashing": "all"
diff --git a/src/test/resources/projects/angular/empty-angular.json b/src/test/resources/projects/angular/empty-angular.json
index c4baa9daf..83ec856c3 100644
--- a/src/test/resources/projects/angular/empty-angular.json
+++ b/src/test/resources/projects/angular/empty-angular.json
@@ -46,19 +46,19 @@
                   "maximumError": "4kb"
                 }
               ],
-              "fileReplacements": [
-                {
-                  "replace": "src/main/webapp/environments/environment.ts",
-                  "with": "src/main/webapp/environments/environment.prod.ts"
-                }
-              ],
               "outputHashing": "all"
             },
             "development": {
               "optimization": false,
               "extractLicenses": false,
               "sourceMap": true,
-              "namedChunks": true
+              "namedChunks": true,
+              "fileReplacements": [
+                {
+                  "replace": "src/main/webapp/environments/environment.ts",
+                  "with": "src/main/webapp/environments/environment.local.ts"
+                }
+              ]
             }
           },
           "defaultConfiguration": "production"
diff --git a/src/test/resources/projects/angular/environment.prod.ts b/src/test/resources/projects/angular/environment.local.ts
similarity index 60%
rename from src/test/resources/projects/angular/environment.prod.ts
rename to src/test/resources/projects/angular/environment.local.ts
index c9669790b..a20cfe557 100644
--- a/src/test/resources/projects/angular/environment.prod.ts
+++ b/src/test/resources/projects/angular/environment.local.ts
@@ -1,3 +1,3 @@
 export const environment = {
-  production: true,
+  production: false,
 };
diff --git a/src/test/resources/projects/angular/environment.ts b/src/test/resources/projects/angular/environment.ts
index a20cfe557..c9669790b 100644
--- a/src/test/resources/projects/angular/environment.ts
+++ b/src/test/resources/projects/angular/environment.ts
@@ -1,3 +1,3 @@
 export const environment = {
-  production: false,
+  production: true,
 };