Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular (全新角度项目)当我将模块导入到独立功能模块时,main.js文件的大小会增加_Angular - Fatal编程技术网

Angular (全新角度项目)当我将模块导入到独立功能模块时,main.js文件的大小会增加

Angular (全新角度项目)当我将模块导入到独立功能模块时,main.js文件的大小会增加,angular,Angular,我有一个新的角度与3个模块的项目应用模块,核心模块和测试模块 CoreModule和TestModule与AppModule没有任何关联或导入 CoreModule延迟加载TestModule 问题: 如果我将任何模块(如HttpClientModule等)导入TestModule,则main.js文件的大小会增加。我的理解是,只有AppModule的内容应该影响main.js的大小,而不是任何功能模块(TestModule) 在TestModule中,如果您在ng build--prod之

我有一个新的角度与3个模块的项目<代码>应用模块,
核心模块
测试模块

  • CoreModule
    TestModule
    AppModule
    没有任何关联或导入
  • CoreModule
    延迟加载
    TestModule
  • 问题:

    如果我将任何模块(如
    HttpClientModule
    等)导入
    TestModule
    ,则
    main.js
    文件的大小会增加。我的理解是,只有
    AppModule
    的内容应该影响
    main.js
    的大小,而不是任何功能模块(
    TestModule

    TestModule
    中,如果您在
    ng build--prod之后注释模块导入,
    main.js
    size=182kb(=51kb gzip)

    TestModule
    中,如果取消注释模块导入,
    ng build--prod

    代码:

    AppModule

    import {NgModule} from '@angular/core';
    import {AppComponent} from './app.component';
    import {BrowserModule} from '@angular/platform-browser';
    
    @NgModule({
      declarations: [
        AppComponent,
      ],
      imports: [
        BrowserModule,
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule {
    }
    
    import {Route, RouterModule} from '@angular/router';
    import {CoreWrapperComponent} from './core-wrapper.component';
    import {NgModule} from '@angular/core';
    
    
    const routes: Route[] = [
      {
    
        path: '',
        component: CoreWrapperComponent,
        children: [{
          path: 'test', loadChildren: './test.module#TestModule', canLoad: []
        }],
      },
      {path: '', redirectTo: `core/viewbots/test`, pathMatch: 'full'},
    ];
    
    declare let areReducersRegistered;
    
    @NgModule({
      declarations: [CoreWrapperComponent],
      entryComponents: [],
      imports: [
        RouterModule.forChild(routes),
      ],
      providers: []
    })
    export class CoreModule {
    }
    
    import {NgModule} from '@angular/core';
    import {Route, RouterModule} from '@angular/router';
    import {CommonModule} from '@angular/common';
    import {HttpClientModule} from '@angular/common/http';
    import {FormsModule, ReactiveFormsModule} from '@angular/forms';
    
    const routes: Route[] = [];
    
    @NgModule({
      declarations: [],
      entryComponents: [],
      imports: [
        CommonModule,
    
        /*
        * If you comment following Module main.js size = 182kb (= 51kb gzip)
        * If you uncomment following Module main.js size = 195kb (= 54.6kb gzip)
        *
        * Since TestModule is not imported in AppModule in any way, adding or removing modules
        * in TestModule should have no impact on main.js file size
        * */
        // RouterModule,
        // HttpClientModule,
        // FormsModule,
        // ReactiveFormsModule,
      ],
    })
    export class TestModule {
    }
    
    核心模块

    import {NgModule} from '@angular/core';
    import {AppComponent} from './app.component';
    import {BrowserModule} from '@angular/platform-browser';
    
    @NgModule({
      declarations: [
        AppComponent,
      ],
      imports: [
        BrowserModule,
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule {
    }
    
    import {Route, RouterModule} from '@angular/router';
    import {CoreWrapperComponent} from './core-wrapper.component';
    import {NgModule} from '@angular/core';
    
    
    const routes: Route[] = [
      {
    
        path: '',
        component: CoreWrapperComponent,
        children: [{
          path: 'test', loadChildren: './test.module#TestModule', canLoad: []
        }],
      },
      {path: '', redirectTo: `core/viewbots/test`, pathMatch: 'full'},
    ];
    
    declare let areReducersRegistered;
    
    @NgModule({
      declarations: [CoreWrapperComponent],
      entryComponents: [],
      imports: [
        RouterModule.forChild(routes),
      ],
      providers: []
    })
    export class CoreModule {
    }
    
    import {NgModule} from '@angular/core';
    import {Route, RouterModule} from '@angular/router';
    import {CommonModule} from '@angular/common';
    import {HttpClientModule} from '@angular/common/http';
    import {FormsModule, ReactiveFormsModule} from '@angular/forms';
    
    const routes: Route[] = [];
    
    @NgModule({
      declarations: [],
      entryComponents: [],
      imports: [
        CommonModule,
    
        /*
        * If you comment following Module main.js size = 182kb (= 51kb gzip)
        * If you uncomment following Module main.js size = 195kb (= 54.6kb gzip)
        *
        * Since TestModule is not imported in AppModule in any way, adding or removing modules
        * in TestModule should have no impact on main.js file size
        * */
        // RouterModule,
        // HttpClientModule,
        // FormsModule,
        // ReactiveFormsModule,
      ],
    })
    export class TestModule {
    }
    
    测试模块

    import {NgModule} from '@angular/core';
    import {AppComponent} from './app.component';
    import {BrowserModule} from '@angular/platform-browser';
    
    @NgModule({
      declarations: [
        AppComponent,
      ],
      imports: [
        BrowserModule,
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule {
    }
    
    import {Route, RouterModule} from '@angular/router';
    import {CoreWrapperComponent} from './core-wrapper.component';
    import {NgModule} from '@angular/core';
    
    
    const routes: Route[] = [
      {
    
        path: '',
        component: CoreWrapperComponent,
        children: [{
          path: 'test', loadChildren: './test.module#TestModule', canLoad: []
        }],
      },
      {path: '', redirectTo: `core/viewbots/test`, pathMatch: 'full'},
    ];
    
    declare let areReducersRegistered;
    
    @NgModule({
      declarations: [CoreWrapperComponent],
      entryComponents: [],
      imports: [
        RouterModule.forChild(routes),
      ],
      providers: []
    })
    export class CoreModule {
    }
    
    import {NgModule} from '@angular/core';
    import {Route, RouterModule} from '@angular/router';
    import {CommonModule} from '@angular/common';
    import {HttpClientModule} from '@angular/common/http';
    import {FormsModule, ReactiveFormsModule} from '@angular/forms';
    
    const routes: Route[] = [];
    
    @NgModule({
      declarations: [],
      entryComponents: [],
      imports: [
        CommonModule,
    
        /*
        * If you comment following Module main.js size = 182kb (= 51kb gzip)
        * If you uncomment following Module main.js size = 195kb (= 54.6kb gzip)
        *
        * Since TestModule is not imported in AppModule in any way, adding or removing modules
        * in TestModule should have no impact on main.js file size
        * */
        // RouterModule,
        // HttpClientModule,
        // FormsModule,
        // ReactiveFormsModule,
      ],
    })
    export class TestModule {
    }
    

    嗯,你有没有和Webpack Bundle Analyzer联系过?我在这里得到了答案:嗯,你有没有和Webpack Bundle Analyzer联系过?我在这里得到了答案: