简体   繁体   English

角度延迟加载 - 看不到它在工作

[英]Angular lazy loading - don't see it is working

I defined a lazy loading module.我定义了一个延迟加载模块。

this is SettingsRoutingModule module-这是 SettingsRoutingModule 模块-

 const routes: Routes = [
        {
            path: '',
            component: SettingsStandaloneComponent,
            children: [
                {
                    path: '',
                    redirectTo: 'profile',
                    pathMatch: 'full'
                },
                {
                    path: 'profile',
                    component: SettingsProfileComponent
                },
                {
                    path: 'about',
                    component: SettingsAboutComponent
                },
                {
                    path: 'affiliations',
                    component: SettingsAffiliationsComponent
                },
                {
                    path: 'communication',
                    component: SettingsCommunicationComponent
                },
                {
                    path: 'notifications',
                    component: SettingsNotificationsComponent
                },
                {
                    path: 'proxies',
                    component: SettingsProxiesComponent
                },
                {
                    path: '**',
                    redirectTo: 'profile',
                    pathMatch: 'full'
                }
            ]
        }
    ];

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

in the AppRoutingModule module-在 AppRoutingModule 模块中 -

{ path: 'settings',
    loadChildren: './settings/settings.module#SettingsModule',
    canActivate: [AuthGuard],
},

in the prod production when a go to the network I don't see the "chunk.js" that everybody say that should appear". only two files that looks like- 0.34016a93d44e785b623a.js在进入网络时的产品生产中,我没有看到每个人都说应该出现的“chunk.js”。只有两个文件看起来像 - 0.34016a93d44e785b623a.js

In my localhost I see only "settings-settings-module.js"在我的本地主机中,我只看到“settings-settings-module.js”

Is it OK or does it mean that my module isn't lazy?可以吗,或者这是否意味着我的模块不懒惰?

Because of this option "namedChunks": false in your angular.json, you won't see the named chunks anymore, instead it displays hashed-value as the file name.由于这个选项"namedChunks": false在你的 angular.json 中,你不会再看到命名的块,而是显示哈希值作为文件名。 This is due to recent improvements(not sure from when) in angular/cli.这是由于最近在 angular/cli 中的改进(不确定从什么时候开始)。

Yes it is OK, We do not see chunk.js anymore.是的,没关系,我们再也看不到 chunk.js 了。 A lazy loaded module appears with its name in network tab as mentioned by you and it appears only once for the first time.延迟加载的模块以其名称出现在您提到的网络选项卡中,并且仅第一次出现。 To see it again, clear everything out by clicking the circle with a line through it in the upper left of the Network Tab:要再次查看它,请单击“网络”选项卡左上角带有一条线的圆圈清除所有内容:

延迟加载模块

Make sure you're not filtering anything in Chrome Debugging tools in Network tab, it was driving me insane for a moment, I had everything set up perfectly.确保您没有在“网络”选项卡中的 Chrome 调试工具中过滤任何内容,这让我发疯了一会儿,我已经完美地设置了所有内容。

Proof (I had 'fa' being filtered, that's why I couldn't see )证明(我过滤了“fa”,这就是我看不到的原因) 证明(我过滤了“fa”,这就是我看不到的原因)

After后

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM