Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 6.4.1 environment builds not working

So trying to do 'npm run ng build --configuration=production' and trying to get it to use the FileReplacements in my angular.json to replace the environment.ts file with environment.prod.ts

I am using following versions:

"@angular/animations": "^8.0.0-beta.12",
"@angular/cdk": "~7.3.7",
"@angular/common": "^8.0.0-beta.12",
"@angular/compiler": "^8.0.0-beta.12",
"@angular/core": "^8.0.0-beta.12",
"@angular/forms": "^8.0.0-beta.13",
"@angular/material": "^7.3.7",

When I run the command above to set configuration of build, in the dist folder, I am still seeing the URL referenced in environment.ts not the environment.prod.ts in the main-es5.js file.

src/environments/environment.ts

export const environment = {
  production: false,
  baseUrl: 'http://0.0.0.0'
  
};

src/environments/environment.prod.ts

export const environment = {
  production: true,
  baseUrl: 'http://1.1.1.1'
};

If anyone sees anything I am doing wrong please let me know. Having to change the URL and other variables is a pain every time I do a build. Thank you!

angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "NewProject": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/NewProject",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/custom-theme.scss",
              "src/styles.css",
              "node_modules/ag-grid-community/dist/styles/ag-grid.css",
              "node_modules/ag-grid-community/dist/styles/ag-theme-balham.css"
            ],
            "scripts": [],
            "es5BrowserSupport": true
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "NewProject:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "NewProject:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "NewProject:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "NewProject:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "NewProject:serve:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "NewProject"
}
like image 871
James Giordano Avatar asked Jun 26 '20 19:06

James Giordano


1 Answers

Running npm run ng build --configuration=production will NOT pass extra arguments to the ng build task. It'll just call ng build

If you want to build for production, you can use ng build --configuration=production

Note: if you really want to use npm run ... to build for production, you need to change the way you sens parameters, as explained here and use -- to separate arguments to send to the task

npm run ng build -- --configuration=production
like image 114
David Avatar answered Sep 27 '22 19:09

David