nodejs 模块加载
2017-11-07 18:29:13 0 举报
通过图表的方式展示nodejs加载模块系统的顺序
作者其他创作
大纲/内容
If X.json is a file
LOAD_AS_DIRECTORY
LOAD_AS_FILE(M)
require(X) from module at path Y
no
yes
let M = X + (json main field)
LOAD_INDEX(X)
If X.node is a file
If X.jx is a file
If X/index.json
If X begins with '/'
If X is a core module
return the core module
set Y to be the filesystem root
LOAD_AS_DIRECTORY(Y+x)
将x当做文件加载
not found
返回模块
THROW \"not found\"
If X begins with './' or '/' or '../'
LOAD_AS_FILE
If X/package.json is a file
If X is a file
主流程
将当前模块当做 文件夹处理
If X/index.node
从node_module中加载模块
0 条评论
下一页