You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(function(modules){// webpackBootstrap// The module cachevarinstalledModules={};// The require functionfunction__webpack_require__(moduleId){// Check if module is in cacheif(installedModules[moduleId]){returninstalledModules[moduleId].exports;}// Create a new module (and put it into the cache)varmodule=(installedModules[moduleId]={i: moduleId,l: false,exports: {},});// Execute the module functionmodules[moduleId].call(module.exports,module,module.exports,__webpack_require__,);// Flag the module as loadedmodule.l=true;// Return the exports of the modulereturnmodule.exports;}// 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,{enumerable: true,get: getter});}};// define __esModule on exports__webpack_require__.r=function(exports){if(typeofSymbol!=='undefined'&&Symbol.toStringTag){Object.defineProperty(exports,Symbol.toStringTag,{value: 'Module'});}Object.defineProperty(exports,'__esModule',{value: true});};// create a fake namespace object// mode & 1: value is a module id, require it// mode & 2: merge all properties of value into the ns// mode & 4: return value when already ns object// mode & 8|1: behave like require__webpack_require__.t=function(value,mode){if(mode&1)value=__webpack_require__(value);if(mode&8)returnvalue;if(mode&4&&typeofvalue==='object'&&value&&value.__esModule)returnvalue;varns=Object.create(null);__webpack_require__.r(ns);Object.defineProperty(ns,'default',{enumerable: true,value: value});if(mode&2&&typeofvalue!='string')for(varkeyinvalue)__webpack_require__.d(ns,key,function(key){returnvalue[key];}.bind(null,key),);returnns;};// getDefaultExport function for compatibility with non-harmony modules__webpack_require__.n=function(module){vargetter=module&&module.__esModule
? functiongetDefault(){returnmodule['default'];}
: functiongetModuleExports(){returnmodule;};__webpack_require__.d(getter,'a',getter);returngetter;};// Object.prototype.hasOwnProperty.call__webpack_require__.o=function(object,property){returnObject.prototype.hasOwnProperty.call(object,property);};// __webpack_public_path____webpack_require__.p='';// Load entry module and return exportsreturn__webpack_require__((__webpack_require__.s='./src/index.js'));})(/************************************************************************/{/***/'./src/index.js':
/*!**********************!*\ !*** ./src/index.js ***! \**********************//*! exports provided: default *//***/function(module,__webpack_exports__,__webpack_require__){'use strict';eval('__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _mark__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./mark */ "./src/mark.js");\n\n\nconst name = \'jack\';\nObject(_mark__WEBPACK_IMPORTED_MODULE_0__["default"])();\n/* harmony default export */ __webpack_exports__["default"] = (name);\n\n\n//# sourceURL=webpack:///./src/index.js?',);/***/},/***/'./src/mark.js':
/*!*********************!*\ !*** ./src/mark.js ***! \*********************//*! exports provided: default *//***/function(module,__webpack_exports__,__webpack_require__){'use strict';eval('__webpack_require__.r(__webpack_exports__);\n/* harmony default export */ __webpack_exports__["default"] = (() => {\n console.log(\'jaja\')\n});\n\n\n//# sourceURL=webpack:///./src/mark.js?',);/***/},},);
定义 mark.js
index.js
下面的代码是 webpack 打包后生成的代码
一步一步来看, 整体是个立即执行函数, 精简下如下
传入立即执行函数的 modules 对应的就是一个对象,对象的 key 是文件路径,value 是函数,函数参数为 module, webpack_exports, webpack_require. 函数内部是用使用 eval 执行,单独拿出来看下。
eval index
eval mark
可以看到,是通过__webpack_require__ 去加载模块,并且将我们的变量 name 赋值给 webpack_exports 的 default 属性上。至于 webpack_require.r 我们稍后分析。
接下来 看看 立即执行函数内部做了什么
eval 里主要使用了 webpack_require.r(webpack_exports)
这里的 webpack_exports 就是 webpack_require 函数里的 module.exports
webpack_require.d
通过__webpack_require__.d 对 module.exports 对象上赋值
也就是 eval 里的执行完以后,我们的 module.exports.default = name
分别打印 index.js 和 mark.js 对应的 module
至于 bundle.js 中的其他内容,都是些辅助函数,暂不分析了。
梳理下 webpack bundle.js 里的流程
The text was updated successfully, but these errors were encountered: