首页 > 解决方案 > are node modules dependency lazy loaded?

问题描述

My question is are the node modules dependencies are lazy loaded in any way? or it's just the magic of imports?

As I have built a git submodule and doing Lazy Loading using react-loadable but it hardly seems to work.

标签: reactjsnode-modulesgit-submodules

解决方案


Node_Modules 不是延迟加载的。在这里,您使用react-loadable的只是 JS/JSX 文件中的动态导入。每当 webpack 在 js 文件中找到 import 语句时,它都会创建块文件并将引用添加到主 js 文件中。在浏览器网络选项卡中,您可以看到多个文件。

react-loadable对于大型项目很有用,它会有多个页面。那个时候把所有的js打包成一个文件并不是一个好习惯。在这种情况下,react-loadable创建多个块并在组件需要出现在屏幕上时加载。


推荐阅读