webpack中bundle、chunk、module的区别

webpack

Webpack Glossary
  1. bundle

    Bundle: Produced from a number of distinct modules, bundles contain the final versions of source files that have already undergone the loading and compilation process.

    译:Bundle:由许多不同的modules生成,包含了源码处理后的最终版本——源码被加载和编译处理;

  2. chunk

    Chunk: This webpack-specific term is used internally to manage the bundling process. Bundles are composed out of chunks, of which there are several types (e.g. entry and child). Typically, chunks directly correspond with the output bundles however, there are some configurations that don’t yield a one-to-one relationship.

    译:chunk:该webpack专业术语用于webpack内部管理bundling的过程中。bundles由许多的chunks组成——这些chunk有不同的类型(比如entrychild)。通常,chunks直接与bundles相对应。然而,有一些配置可以使其不是一对一的关系;

  3. module

    Module: Discrete chunks of functionality that provide a smaller surface area than a full program. Well-written modules provide solid abstractions and encapsulation boundaries which make up a coherent design and clear purpose.

    译:module:非连续的功能块——提供了更小的表面积而不是整个程序。书写良好的modules提供了可靠的抽象及封装边界,组成了统一的设计和清晰的目的;

结合stackoverflow释疑

modulewebpack支持解析的模块;
chunk包含多个module,存在于webpack处理过程中的阶段;
bundle包含一个或多个chunk,是源码经过webpack处理后的最终版本;

The distinction is useful when talking about webpack processes as they are occuring. As modules are chunked together, they can change significantly (especially during plugin processing), so it isn’t accurate to call them bundles at that point, the chunks may not even be emitted as bundles in the final output! Then after webpack is finished it is useful to have a term to refer to all of the emitted, final files (bundles).

译: 这样的区分对于描述webpack的处理过程是有帮助的。由于多个module被组合为一个chunk,他们能够有效地改变(尤其是在插件处理过程中),所以这个时间节点把它们称为bundle并不准确,而且这些chunks可能不会称为最终输出中的bundles!当webpack处理结束后,有必要使用一个术语去表示它的最终输出文件(bundles

析: 这里应该是——所以这个时间节点把它们称为module并不准确;module通常是与源码相关的,webpack将多个module合并为一个chunk,然后进行统一处理有助于提高效率,比如统一进行babel转移等插件操作,所以webpack处理过程中使用了术语chunk表示这些文件;由于不是所有的chunks都会称为最终的输出文件,所以又定义了一个新的术语——bundle


参考文献

  1. Webpack Glossary
  2. stackoverflow
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章