E:/project/超过了最大预算,出现了错误

8

早上好,我已经创建了我的项目,现在想要使用“ng build --prod”命令输出,但是遇到了错误。我该如何解决这个问题呢?我猜测问题来自以下代码,但我不知道怎么修复它。

    "budgets": [
         {
         "type": "initial",
         "maximumWarning": "2mb",
         "maximumError": "5mb"
         },
         {
         "type": "anyComponentStyle",
         "maximumWarning": "6kb",
         "maximumError": "10kb"
         }
    ]

终端显示错误:

ng build --prod

    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/layout-dialog/dialog-successful/dialog-successful.component.scss. Budget 6 kB was not met by 17.4 kB with a total of 23.4 kB.
    
    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/login/login.component.scss. Budget 6 kB was not met by 201 kB with a total
    of 207 kB.
    
    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/home/about-me/about-me.component.scss. Budget 6 kB was not met by 201 kB with a total of 207 kB.
    
    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/header-admin/header-admin.component.scss. Budget 6 kB was not met by
    201 kB with a total of 207 kB.
    
    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/home/show-documents/show-documents.component.scss. Budget 6 kB was not met
    by 201 kB with a total of 207 kB.
    
    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/home/show-expertise/show-expertise.component.scss. Budget 6 kB was not met
    by 204 kB with a total of 210 kB.
    
    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/home/show-records/show-records.component.scss. Budget 6 kB was not met by 200 kB with a total of 206 kB.
    
    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/home/contact-me/contact-me.component.scss. Budget 6 kB was not met by 202 kB with a total of 208 kB.
    
    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/about-me-admin/about-me-admin.component.scss. Budget 6 kB was
    not met by 201 kB with a total of 207 kB.
    
    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/documents-admin/documents-admin.component.scss. Budget 6 kB was not met by 201 kB with a total of 207 kB.
    
    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/expertise-admin/expertise-admin.component.scss. Budget 6 kB was not met by 204 kB with a total of 210 kB.
    
    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/messages-admin/messages-admin.component.scss. Budget 6 kB was
    not met by 200 kB with a total of 206 kB.
    
    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/records-admin/records-admin.component.scss. Budget 6 kB was not met by 201 kB with a total of 207 kB.
    
    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/home/home.component.scss. Budget 6 kB was not met by 225 kB with a total of 231 kB.
    
    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/records-admin/ae-record/ae-record.component.scss. Budget 6 kB
    was not met by 201 kB with a total of 207 kB.
    
    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/documents-admin/ae-documents/ae-documents.component.scss. Budget 6 kB was not met by 200 kB with a total of 206 kB.
    
    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/about-me-admin/edit-about-me-admin/edit-about-me-admin.component.scss. Budget 6 kB was not met by 201 kB with a total of 207 kB.
    
    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/expertise-admin/ae-expertise/ae-expertise.component.scss. Budget 6 kB was not met by 201 kB with a total of 207 kB.
    
    WARNING in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/layout-dialog/dialog-delete/dialog-delete.component.scss. Budget 6 kB was not met by 224 kB with a total of 230 kB.
    
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/layout-dialog/dialog-successful/dialog-successful.component.scss. Budget 10 kB was not met by 13.4 kB with a total of 23.4 kB.
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/login/login.component.scss. Budget 10 kB was not met by 197 kB with a total of 207 kB.
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/home/about-me/about-me.component.scss. Budget 10 kB was not met by 197 kB with a total of 207 kB.
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/header-admin/header-admin.component.scss. Budget 10 kB was not met by 197 kB with a total of 207 kB.
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/home/show-documents/show-documents.component.scss. Budget 10 kB was not met by 197 kB with a total of 207 kB.
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/home/show-expertise/show-expertise.component.scss. Budget 10 kB was not met by 200 kB with a total of 210 kB.
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/home/show-records/show-records.component.scss. Budget 10 kB was not met by 196 kB with a total of 206 kB.
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/home/contact-me/contact-me.component.scss. Budget 10 kB was not met by 198 kB with a total of 208 kB.
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/about-me-admin/about-me-admin.component.scss. Budget 10 kB was not met by 197 kB with a total of 207 kB.
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/documents-admin/documents-admin.component.scss. Budget 10 kB was not met by 197 kB with a total of 207 kB.
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/expertise-admin/expertise-admin.component.scss. Budget 10 kB was not met by 200 kB with a total of 210 kB.
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/messages-admin/messages-admin.component.scss. Budget 10 kB was not met by 196 kB with a total of 206 kB.
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/records-admin/records-admin.component.scss. Budget 10 kB was not met by 197 kB with a total of 207 kB.
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/home/home.component.scss. Budget 10 kB was not met by 221 kB with a total of
    231 kB.
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/records-admin/ae-record/ae-record.component.scss. Budget 10 kB was not met by 197 kB with a total of 207 kB.
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/documents-admin/ae-documents/ae-documents.component.scss. Budget 10 kB was not met by 196 kB with a total of 206 kB.
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/about-me-admin/edit-about-me-admin/edit-about-me-admin.component.scss. Budget 10 kB was not met by 197 kB with a total of 207 kB.
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/expertise-admin/ae-expertise/ae-expertise.component.scss. Budget 10 kB was not met by 197 kB with a total of 207 kB.
    ERROR in Exceeded maximum budget for E:/project/PwpEnd/PWP/src/app/layout/admin/layout/layout-dialog/dialog-delete/dialog-delete.component.scss. Budget 10 kB was not met by 220 kB with a total of 230 kB.

angular.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "PWP": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/PWP",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss",
              "./node_modules/bootstrap/dist/css/bootstrap.css"
            ],
            "scripts": [
              "./node_modules/bootstrap/dist/js/bootstrap.js",
              "./node_modules/bootstrap/dist/js/bootstrap.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,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "PWP:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "PWP:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "PWP:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "PWP:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "PWP:serve:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "PWP",
  "cli": {
    "analytics": "c792c032-9136-42b5-8b0a-391b6f8d84c5"
  }
}

pakege.json:

{
  "name": "pwp",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~9.1.7",
    "@angular/cdk": "^9.2.4",
    "@angular/common": "~9.1.7",
    "@angular/compiler": "~9.1.7",
    "@angular/core": "~9.1.7",
    "@angular/forms": "~9.1.7",
    "@angular/material": "^9.2.4",
    "@angular/platform-browser": "~9.1.7",
    "@angular/platform-browser-dynamic": "~9.1.7",
    "@angular/router": "~9.1.7",
    "bootstrap": "^4.6.0",
    "jquery": "^3.5.1",
    "jspdf": "^2.3.0",
    "ngx-cookie-service": "^11.0.2",
    "rxjs": "~6.5.4",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.901.6",
    "@angular/cli": "~9.1.6",
    "@angular/compiler-cli": "~9.1.7",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/jspdf": "^1.3.3",
    "@types/node": "^12.11.1",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~5.0.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~3.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "protractor": "~5.4.3",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~3.8.3"
  }
}

app.routing.module.ts:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { ValidTokenRoutingGuard } from './valid-token-routing/valid-token-routing-guard';
const routes: Routes = [
  { path: '', loadChildren: () => import('./layout/home/home.module').then(m => m.HomeModule) },
  { path: 'Admin', canActivate: [ValidTokenRoutingGuard], loadChildren: () => import('./layout/admin/admin.module').then(m => m.AdminModule) },
  { path: 'Login', loadChildren: () => import('./layout/login/login.module').then(m => m.LoginModule) },
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    HttpClientModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})

只是...增加预算吗? - MikeOne
1个回答

15

这是一个编译器错误,因此您会注意到您的文件大小小于定义的大小。只需在angular.json中修改配置并将maximumError大小属性增加到适合您的需求,然后再次构建即可。我还建议您检查项目以删除任何未使用的代码或依赖项,以减小文件大小。


谢谢,我的问题已经解决了,我采用了这种方法来加快网站首次加载速度。 但是仍然有一些缓慢的问题存在。 怎么办呢? - user15147989
你应该在Angular应用程序中使用惰性加载,这样只有在导航到其路由时才会加载其余的特性模块,从而减少初始加载时间和块大小。当应用程序较大时,这是必须的 - 请查看此文档:https://angular.io/guide/lazy-loading-ngmodules - Dani P.
如果你只是在谈论编译,现代的Angular使用增量编译器,因此第一次构建应用程序需要更长时间,之后速度会更快。 - Dani P.
正如您所看到的,我使用了懒加载,但它仍然加载得很晚。 - user15147989
无论如何,这不会影响浏览器的加载时间,它只是在构建应用程序时设置警告和错误。 如果您的应用程序加载缓慢,您必须检查逻辑、性能、浏览器、计算机等。使用Chrome Dev工具。 我的Angular 10应用程序在2-3秒内启动,而且非常大。 对于轻量级应用程序,老实说,我建议使用其他框架。 - Dani P.
显示剩余4条评论

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