简体   繁体   English

为什么webpack向'__webpack_require__'函数添加属性?

[英]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.

相关问题 __webpack_require__(...).context 不是 function - __webpack_require__(...).context is not a function 未捕获的类型错误:__webpack_require__(...).context 不是 function - Uncaught TypeError: __webpack_require__(...).context is not a function TypeError: __webpack_require__(...).context 不是 function - 硬编码但不带参数 - TypeError: __webpack_require__(…).context is not a function - Works hardcoded but not with parameter 诊断未捕获的TypeError:__webpack_require __(…).createServer不是函数? - Diagnosing Uncaught TypeError: __webpack_require__(…).createServer is not a function? 在 __webpack_require__ 中的 NextJS 中构建错误 - Build errors in NextJS in __webpack_require__ 未在反射元数据上定义需求-__webpack_require__问题 - Require is not defined on reflect-metadata - __webpack_require__ issue 未捕获的类型错误:无法读取 __webpack_require__ 处未定义的属性“调用” - Uncaught TypeError: Cannot read property 'call' of undefined at __webpack_require__ React - ssh2 模块错误:未捕获的类型错误:__webpack_require__(...).constants 未定义 - React - ssh2 module Error: Uncaught TypeError: __webpack_require__(…).constants is undefined Vue.js 应用程序在 Chrome 中显示正常,但在 Firefox 中显示空白页 - __webpack_require__ 错误 - Vue.js App showing fine in Chrome, but shows blank page in Firefox - __webpack_require__ error WebPack和Require - WebPack and Require
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM