4

尝试在 prod 模式下构建 Angular 应用程序,但发现未知目标和环境错误。

尝试以下:

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

我期望构建文件,如 main.js、vendor.js 等。输出是:

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

4 回答 4

1
ng build --configuration=staging
ng server --configuration=staging

确保您在环境文件夹中创建一个environment.staging文件,并修改该angular.json文件以允许此命令。

"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"
        }
      }
    },
于 2020-07-02T01:00:29.797 回答
1

ng build --prod 是生产环境的默认构建命令,不需要其他参数,只要有特定的你需要实现例如如果你有另一个环境你可以运行

ng build --c= staging其中 c 代表配置这里是更多选项 https://angular.io/cli/build

于 2019-04-02T09:09:43.897 回答
1

您可以使用此构建命令 ng build --base-href="/" --env=prod

于 2019-04-02T06:00:37.637 回答
0

发现以下命令在没有任何参数的情况下执行良好:

ng build --prod

输出:

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]
于 2019-04-02T05:59:24.680 回答