代码之家  ›  专栏  ›  技术社区  ›  ufk

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

  •  0
  • ufk  · 技术社区  · 7 年前

    我使用angularcli6.2.4项目并创建了angular6项目。

    我想我需要执行 ng build --configuration=production

    但这给了我以下错误:

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

    跑步 ng build 没有任何参数不会给我任何问题。

    src/environments environment.dev.ts 除此之外 environment.prod.ts 已经存在了。

    这是我的完整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"
    }
    

    1 回复  |  直到 7 年前
        1
  •  0
  •   ufk    7 年前

    我本来应该从一开始就听“Suresh Kumar Ariya”的,但这个话题让我有点困惑。

    @user184994也帮助了我,在第五次阅读这篇文章后,我真的应该检查我的提供者,因为这是一个问题,只有当我使用AOT时才能检测到。

    所以不管怎样我用 Document 作为一个提供者,我在某个地方读到为了使用 document 这是假的。去掉它就解决了问题

    谢谢大家