tendersun

webpack
tendersun
Dec 17
Commonjs实现原理let modules = { "./name.js": (module) => { module.exports = 'name'; } } let cache = {}; // 内存中的缓存对象 function require(modulePath) { let moduleCache = cache(modulePath); // 如果之前加载过该模板,直接返回缓存 if (moduleCache) { return moduleCache; } // moduleCache和module指向同一个引用 let module = (moduleCache = { exports: {} }) // 运行模块中的代码,给module赋值 modulesmodulePath; return module.exports; } https://juejin.cn/post/7147365025047379981/#heading-6
ParagraphParagraph

tendersun

Written by
sy739014282
Subscribe

2025 Paragraph Technologies Inc

PopularTrendingPrivacyTermsHome
Search...Ctrl+K
Subscribe