高级前端
node
【Q290】Node 中 require 时发生了什么

Node 中 require 时发生了什么

Issue 欢迎在 Gtihub Issue 中回答此问题: Issue 292 (opens in a new tab)

Author 回答者: haotie1990 (opens in a new tab)

http://nodejs.cn/api/modules.html#modules_all_together (opens in a new tab)

Author 回答者: maya1900 (opens in a new tab)

3个步骤:路径分析、模块定位、编译执行

按顺序加载:系统缓存→系统模块→文件模块→目录模块→node_modules目录