0
votes

It seems after recently upgrading from angular 7 to angular 8 my app does not build properly with different environments.

For example i want to build using the test environment.

npm run build --configuration=test

angular.json

"configurations": {
                "production": {
                    "index": "src/production/index.html",
                    "optimization": true,
                    "outputHashing": "all",
                    "sourceMap": false,
                    "extractCss": true,
                    "namedChunks": false,
                    "aot": true,
                    "extractLicenses": true,
                    "vendorChunk": false,
                    "buildOptimizer": true,
                    "fileReplacements": [
                        {
                            "replace": "src/environments/environment.ts",
                            "with": "src/environments/environment.prod.ts"
                        }
                    ]
                },
                "test": {
                    "index": "src/test/index.html",
                    "optimization": true,
                    "outputHashing": "all",
                    "sourceMap": false,
                    "extractCss": true,
                    "namedChunks": false,
                    "aot": true,
                    "extractLicenses": true,
                    "vendorChunk": false,
                    "buildOptimizer": true,
                    "fileReplacements": [
                        {
                            "replace": "src/environments/environment.ts",
                            "with": "src/environments/environment.test.ts"
                        }
                    ]
                }
            }
        },

However this doesen;'t work and reverts back to the default environment file.

environment.ts

export const environment = {
    production: false,
    build: 'Local',
    ...
};

environment.test.ts

export const environment = {
    production: false,
    build: 'Test',
    ...
};
1
Pretty sure you ran the wrong command npm run build --configuration=test should be using angular cli's command ng build --configuration=test - penleychan
check your package.json file npm run build is the same as ng build. - Kay
Yah but you gotta understand that, running the script from package.json is not the same as running ng build --configuration=test. The package.json contains preset of scripts, in your case for build is ng build. Which means you can't just send additional args with out using -- so npm run build -- --configuration=test would be the same as ng build --configuration=test - penleychan

1 Answers

0
votes

ng build --configuration=test should work. We use the same setup.

Consider the output path in angular.json (under: projects > your-project > architect > build > options > outputPath).