6

Tried to build the angular app in prod mode, but unknown target and environment error found.

Tried with below:

ng build --target=production --base-href /
ng build --target=production --environment=prod
ng build --prod --env=prod

I expected build files like main.js, vendor.js etc.. The out put was :

Unknown option: '--target'
Unknown option: '--environment'

4 Answers4

4
ng build --configuration=staging
ng server --configuration=staging

Ensure you create a environment.staging file in environment folder and also modified the angular.json file to allow this command.

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

"serve": {
      "builder": "@angular-devkit/build-angular:dev-server",
      "options": {
        "browserTarget": "letsfarm-frontend:build"
      },
      "configurations": {
        "production": {
          "browserTarget": "letsfarm-frontend:build:production"
        },
        "staging": {
          "browserTarget": "letsfarm-frontend:build:staging"
        }
      }
    },
Lekens
  • 1,823
  • 17
  • 31
1

You can use this build command ng build --base-href="/" --env=prod

Abhishek Ekaanth
  • 2,511
  • 2
  • 19
  • 40
1

ng build --prod is the default building command for production environment, no need to other parameters, only if there is sth specific you need to achieve For example If you have another environment you can run

ng build --c= staging where c stand for configuration here is further options https://angular.io/cli/build

Kenana Reda
  • 430
  • 1
  • 9
  • 24
0

Found that below command executes well without any arguments:

ng build --prod

Output:

Date: 2019-04-02T05:51:07.034Z
Hash: 13d7def367e6ab28002d
Time: 126225ms
chunk {0} runtime.26209474bfa8dc87a77c.js (runtime) 1.41 kB [entry] [rendered]
chunk {1} es2015-polyfills.c5dd28b362270c767b34.js (es2015-polyfills) 56.4 kB [initial] [rendered]
chunk {2} main.ab6e55257ccc1317a780.js (main) 245 kB [initial] [rendered]
chunk {3} polyfills.8bbb231b43165d65d357.js (polyfills) 41 kB [initial] [rendered]
chunk {4} styles.b0dcfc0155d6280ef171.css (styles) 488 kB [initial] [rendered]