[英]Why webpack add properties to '__webpack_require__' function?
I'm a code beginner and recently I've began to see and try to understand the code and design of some libraries. 我是一个代码初学者,最近我开始看到并尝试理解一些库的代码和设计。 I've noticed that Webpack, when it creates a bundle, use the ' webpack_require ' function to load needed modules but I don't understand why, after the function definition, it add it properties like: 我注意到,Webpack在创建捆绑包时使用“ webpack_require ”函数加载所需的模块,但是我不明白为什么在函数定义之后,它会像以下那样添加属性:
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
Why it add properties to a function instead of create an object? 为什么将属性添加到函数而不是创建对象? Are there advantages in this practice? 这种做法有优势吗? Excuse me for beginner's question. 请问初学者的问题。 Thank you for the answers. 谢谢你的回答。
It's simply a container for the imported modules, and is used only inside the bundle. 它只是导入模块的容器,仅在包内使用。 I personally use source-map
to debug, than reading the uncompressed bundle. 我个人使用source-map
进行调试,而不是读取未压缩的包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.