webpack bundle.js的格式

1. 整个bundle.js打包后,是一个匿名自执行函数,参数是一个数组。

2. 数组每一项都是一个function,function的内容就是每个模块的内容,并按照require的顺序排列。

3. webpack的每个模块都有一个唯一的id,是从0开始递增的,其他模块通过id来引用该模块

具体形式如下:

// bundle.js
/******/ (function(modules) { // webpackBootstrap
/******/    // The module cache
/******/    var installedModules = {};

/******/    // The require function
/******/    function __webpack_require__(moduleId) {
                ......
/******/    }

            ......

/******/    return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
    //通过id引用其他模块
    var b = __webpack_require__(1);

    console.log('a');

    b.b1();


/***/ },
/* 1 */
/***/ function(module, exports) {

    exports.b1 = function () {
      console.log('b1')
    };

    exports.b2 = function () {
      console.log('b2')
    };

/***/ }
/******/ ]);

 

posted @ 2020-03-29 15:29  全玉  阅读(654)  评论(0)    收藏  举报