在运行 ng build --prod 后,为什么没有生成 index.html 文件?

10

我将 Angular 7 更新为 8.2.1 后,在生产模式下构建项目后,dist 文件夹没有生成 index.html 文件。

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "esnext",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "paths": {
      "exceljs": [
        "node_modules/exceljs/dist/exceljs.min"
      ]
    },
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ],

  }
}

Dist/AssetMang/ angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "AssetMang": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/AssetMang",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [],
            "scripts": []
          },
          "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": "5mb",
                  "maximumError": "8mb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "port": 4204,
            "browserTarget": "AssetMang:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "AssetMang:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "AssetMang: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": [
              "src/styles.css"
            ],
            "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/**"
            ]
          }
        }
      }
    },
    "AssetMang-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "prefix": "",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "AssetMang:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "AssetMang:serve:production"
            }
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "AssetMang"
}

请查看是否有遗漏的内容 https://update.angular.io/#7.0:8.0 - SGalea
@SGalea 检查过了,没有遗漏。 - Aakash Shah
1
你能分享一下你的 angular.json 文件吗? - Tony Ngo
@TonyNgo 请检查。 - Aakash Shah
你的正常src/index.html文件存在吗? - mahalde
@Flix 是的,当我只使用 ng build 构建应用程序时,它会生成 index.html 文件。 - Aakash Shah
1个回答

19

正如在问题15175中所解释的那样,请检查您的构建输出。如果存在错误或预算违规,index.html文件将不会生成。

Build at: 2021-07-11T22:17:50.237Z - Hash: 085ada49cbe5750a0a86 - Time: 47523ms

Warning: initial exceeded maximum budget. Budget 500.00 kB was not met by 559.07 kB with a total of 1.03 MB.

Error: initial exceeded maximum budget. Budget 1.00 MB was not met by 35.07 kB with a total of 1.03 MB.

生成索引必须成功构建。


1
这个问题花了我3个小时才找出来,我以为我可以无视那些警告。 - late1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接