AndreGeng/AndreGeng.github.io

webpack概念分析,Bundle vs Chunk

AndreGeng opened this issue · 0 comments

如何理解module, bundle, entry chunk, initial chunk, normal chunk

  1. 我们在代码中的require或者import的都属于module,这点很好理解
  2. bundle是指webpack这种bundler,output生成的那些文件
  3. entry chunk是指包含wepback runtime的chunk
  4. initial chunk是指那些同步加载的,不包含runtime code的chunk. 比如我们通过optimization.runtimeChunk把runtime分离出来后,得到的chunk, 如下:
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([["index"],{

/***/ "./index.js":
/*!******************!*\
  !*** ./index.js ***!
  \******************/
/*! no static exports found */
/***/ (function(module, exports) {

eval("console.log('Hello World!');\n\n\n//# sourceURL=webpack:///./index.js?");

/***/ })

},[["./index.js","runtime"]]]);

  1. normal chunk是指那些通过代码分割点(require.ensure, import(), System.import())生成的那些异步加载的代码。

具体解释可以参见这里:Bundle vs Chunk