Angular Lazyload 路由生成额外的块文件,前缀为 default~pages [英] Angular Lazyload routes generates extra chunk files with prefix default~pages

查看:18
本文介绍了Angular Lazyload 路由生成额外的块文件,前缀为 default~pages的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我目前正在处理的项目实施延迟加载路由.一切正常,我没有收到任何错误,当我转到新页面时,我还可以看到新的块文件加载.

I'm trying to implement lazy loading routes for the project I'm currently working on. everything works and I get no errors, I can also see when I go to new pages new chunk files load.

然而,除了我预期的块文件之外,cli 还创建了一些带有前缀default~pages"的额外文件,例如

however, in addition to my expected chunk files, cli also creates few extra files with prefix "default~pages", such as

default~pages-managers--managers-module~pages-hosts-hosts-module~pa~0e1f5bc0

并且这些带有 default~ 前缀的文件会加载,无论我登陆哪个页面.例如,如果我在主页上,我会同时看到两者:

and these files with default~ prefix load regardless of what page I'm landing on. For example, if I'm on the home page, I see both:

pages-home-home-module

default~pages-managers--managers-module~pages-hosts-hosts-module~pa~0e1f5bc0

有谁知道这些默认文件是什么以及如何摆脱它们?

does anyone know what are these default files are and how to get rid of them?

推荐答案

此评论是 w.r.t.Angular 版本 11.2.1...

This comment is w.r.t. Angular version 11.2.1...

这是一个默认功能(设置为 true),可以在 angular.json 文件中配置(Andre Elrico 已经回答了),但我看到了一个很棒的保持此默认值的好处(即要在网络上加载的包大小和构建时间).下面是一个演示:-

This is a default feature (set to true) that could be configured in angular.json file (Andre Elrico has already answered it), but I see a great benefit of keeping this default (i.e. bundle size(s) to load on the Network and build times). Below is a demonstration: -

有一个共同的块:-

没有共同的块:-

结尾:我可以说 - 使用第二种方法,公共模块将与每个单独的延迟加载模块合并.如果这就是您要找的东西;然后调整 angular.json 文件中的设置.

Outro: I can say- with the 2nd approach, common modules will get merged with each individual lazy-loaded module. If that is what you are looking for; then tweak the settings in angular.json file.

请注意:构建时间取决于操作系统、硬件配置等.

Please Note: The build time is dependant on the Operating System, Hardware Config, etc.

这篇关于Angular Lazyload 路由生成额外的块文件,前缀为 default~pages的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆