简体   繁体   English

如何在特定环境下构建角度cli项目

[英]how to build angular cli project with specific environment

I used angular cli 6.2.4 project and created an angular6 project. 我使用angular cli 6.2.4项目并创建了angular6项目。

I want to use the environment/configuration option to create the specific configuration for dev and prod. 我想使用environment / configuration选项为dev和prod创建特定的配置。

I thought that I need to execute ng build --configuration=production 我以为我需要执行ng build --configuration=production

but that gives me the following error: 但这给了我以下错误:

ERROR in: Encountered undefined provider! Usually, this means you have a circular dependency. This might be caused by using 'barrel' index.ts files.

running ng build without any parameter doesn't give me any issues. 没有任何参数运行ng build不会给我任何问题。

in src/environments I created an environment.dev.ts besides that environment.prod.ts that already existed. src/environments我创建了一个environment.dev.ts除此之外environment.prod.ts已经存在。

this is my full angular.json file: 这是我完整的angular.json文件:

  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "wd-angular-client": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {
        "@schematics/angular:component": {
          "styleext": "scss"
        }
      },
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/wd-angular-client",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              {
                "input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
              },
              "node_modules/font-awesome/scss/font-awesome.scss",
              "node_modules/angular-bootstrap-md/scss/bootstrap/bootstrap.scss",
              "node_modules/angular-bootstrap-md/scss/mdb-free.scss",
              "src/styles.scss"
            ],
            "scripts": [
              "node_modules/chart.js/dist/Chart.js",
              "node_modules/hammerjs/hammer.min.js"
            ]
          },
          "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
            },
            "development": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.dev.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "wd-angular-client:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "wd-angular-client:build:production"
            },
            "development": {
              "browserTarget": "wd-angular-client:build:development"
            }

          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "wd-angular-client:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              {
                "input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
              },
              "src/styles.scss"
            ],
            "scripts": [],
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "wd-angular-client-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "wd-angular-client:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "wd-angular-client:serve:production"
            },
            "development": {
              "devServerTarget": "wd-angular-client:serve:development"
            }
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "wd-angular-client"
}

what am I missing ? 我想念什么?

I should have listened to @Suresh-Kumar-Ariya from the beginning but that subject was a bit confusing form me. 我应该从一开始就听过@ Suresh-Kumar-Ariya,但是这个话题对我来说有点令人困惑。

@user184994 also helped me after reading this post for the 5th time that I really should check my providers since it's a problem only detected when I use AOT. @ user184994第5次阅读这篇文章后也对我有所帮助,我真的应该检查我的提供者,因为这是仅在使用AOT时才发现的问题。

so anyhow I use Document as a provider, I read somewhere that I needed to use that in order to use document which was false. 因此无论如何我都使用Document作为提供者,我读了一些我需要使用的地方才能使用错误的document removing it solved the problem 删除它解决了问题

thanks all 谢谢大家

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM