Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lazyRequire在crn-cli中是什么作用? #59

Open
colinNaive opened this issue Sep 18, 2019 · 1 comment
Open

lazyRequire在crn-cli中是什么作用? #59

colinNaive opened this issue Sep 18, 2019 · 1 comment

Comments

@colinNaive
Copy link

为什么在crn-cli中有一个lazyRequire的实现呢?这个的作用是什么?
global.lazyRequire = lazyRequire; function lazyRequire(requirePath) { var lazy = { __lazyRequireFlag: true, __lazy_module_id__ : requirePath, load : function() { var module = global.__r(this.__lazy_module_id__); return module; } }; return lazy; }
在crn的代码中有看到lazyRequire的实现,主要目的是先定义module,在使用的地方才load,才去真正require相关module。这个是我能理解的,可是crn-cli的作用是打包,为什么打包的时候还需要lazyRequire?
麻烦大佬指教一二。谢谢

@blackwuxin
Copy link
Contributor

打包的时候会执行patch动作,拷贝lazyRequire文件到node_moudles/react-native目录下。这样业务方在使用lazyRequire模块才能找到该文件。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants