首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >警告:预算:初始预算超出了最大预算

警告:预算:初始预算超出了最大预算
EN

Stack Overflow用户
提问于 2020-12-19 04:02:07
回答 2查看 4.5K关注 0票数 6

当我运行npm build --prod时,我得到以下错误

Error: budgets: initial exceeded maximum budget. Budget 1.00 MB was not met by 500.42 kB with a total of 1.49 MB.

我还收到了这样的警告:

Warning: C:\Users\PATH_TO_FILE\socket.service.ts depends on 'socket.io-client'. CommonJS or AMD dependencies can cause optimization bailouts. For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

我还导入了相当多的角度材质模块。这是我的app.module.ts (它是我整个项目中唯一的模块):

代码语言:javascript
复制
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';

import { AppComponent } from './app.component';
import { SocketService } from './services/socket.service';
import { AppRoutingModule } from './app-routing.module';

import { ClipboardModule } from '@angular/cdk/clipboard';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatButtonModule } from '@angular/material/button';
import { MatTooltipModule } from '@angular/material/tooltip';
import { MatIconModule } from '@angular/material/icon';
import { MatChipsModule } from '@angular/material/chips';
import { MatSliderModule } from '@angular/material/slider';
import { MatButtonToggleModule } from '@angular/material/button-toggle';
import { MatDialogModule } from '@angular/material/dialog';

import { AdminPanelComponent } from './components/admin-panel/admin-panel.component';
import { ChatMessageComponent } from './components/chat-message/chat-message.component';
import { ChatPanelComponent } from './components/chat-panel/chat-panel.component';
import { DrawingPanelComponent } from './components/drawing-panel/drawing-panel.component';
import { PlayerComponent } from './components/player/player.component';
import { PlayersPanelComponent } from './components/players-panel/players-panel.component';
import { ToolsPanelComponent } from './components/tools-panel/tools-panel.component';
import { ChatMessageDirective } from './directives/chat-message.directive';
import { PlayerDirective } from './directives/player.directive';
import { GameManagerComponent } from './components/game-manager/game-manager.component';
import { ArtistOptionsComponent } from './components/artist-options/artist-options.component';
import { InfoPanelComponent } from './components/info-panel/info-panel.component';
import { DialogComponent } from './components/dialog/dialog.component';

@NgModule({
  declarations: [
    AppComponent,
    AdminPanelComponent,
    PlayersPanelComponent,
    DrawingPanelComponent,
    ChatPanelComponent,
    PlayersPanelComponent,
    ToolsPanelComponent,
    ChatMessageComponent,
    ChatMessageDirective,
    PlayerDirective,
    PlayerComponent,
    GameManagerComponent,
    ArtistOptionsComponent,
    InfoPanelComponent,
    DialogComponent,
  ],
  imports: [
    BrowserModule,
    FormsModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    FontAwesomeModule,
    ClipboardModule,
    MatFormFieldModule,
    MatInputModule,
    MatButtonModule,
    MatTooltipModule,
    MatIconModule,
    MatChipsModule,
    MatSliderModule,
    MatButtonToggleModule,
    MatDialogModule
  ],
  providers: [SocketService],
  bootstrap: [AppComponent]
})
export class AppModule { }

我如何解决超出最大预算的问题(我认为是socket.io-client模块)?作为一个附带问题:我可以优化app.module.ts文件吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-05-26 23:07:18

这些都是您的angular.json中的配置。找到它,然后查找预算。

现在,您可以根据需要更改其中的值。

例如:

代码语言:javascript
复制
"budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "500kb",
                  "maximumError": "1mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kb",
                  "maximumError": "4kb"
                }
              ],

代码语言:javascript
复制
"budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kb",
                  "maximumError": "4kb"
                }
              ],

您可以给出适合您的限制的值。

票数 10
EN

Stack Overflow用户

发布于 2021-09-06 11:13:25

你总是可以通过增加预算限制来提高门槛,但你应该寻找减少初始预算的方法。您可以使用source-map-explorer来分析应用程序中的每个模块,并确定启动应用程序时真正需要和不重要的模块。

例如,您可以从不需要启动应用程序的应用程序模块中删除一些依赖项和功能,并将这些内容带到一个延迟加载的模块中。这将通过减少初始捆绑包大小来减少应用程序的初始加载时间。

下图是angular应用程序启动时需要的初始包的示例。

如果您需要将source-map-explorer设置为您的项目,请参阅本文。https://dev.to/salimchemes/analyzing-angular-bundle-with-source-map-explorer-341

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65363248

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档