AndreGeng / AndreGeng.github.io

blog repository
1 stars 0 forks source link

webpack概念分析,Bundle vs Chunk #30

Open AndreGeng opened 5 years ago

AndreGeng commented 5 years ago

如何理解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"]]]);


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

具体解释可以参见这里:[Bundle vs Chunk](https://github.com/webpack/webpack.js.org/issues/970#issuecomment-305525560)