Skip to content
This repository was archived by the owner on Mar 22, 2019. It is now read-only.

internal webpack plugins.cn

e-cloud edited this page Mar 28, 2016 · 1 revision

These is a list of plugins, which are internally used by webpack. You should only care about them if you are building a own compiler based on webpack, or introspect the internals.

webpack 内部使用了一组插件。你只应在基于 webpack 构建自己的编译器时才关注它们,或者研究内部对象。

categories of internal plugins:

内部插件类型列表:

  • environment
  • compiler
  • entry
  • output
  • source
  • optimize

environment

Plugins affecting the environment of the compiler.

影响编译器环境的插件。

node/NodeEnvironmentPlugin

Applies node.js style filesystem to the compiler.

把 node.js 风格的文件系统应用到编译器。

compiler

Plugins affecting the compiler

影响编译器的插件。

CachePlugin([cache])

Adds a cache to the compiler, where modules are cached.

向编译器加入缓存,用于缓存模块

You can pass a cache object, where the modules are cached. Otherwise one is created per plugin instance.

你可以传入一个cache对象,来缓存模块。否则,每个插件实例都会创建一个。

ProgressPlugin(handler)

Hook into the compiler to extract progress information. The handler must have the signature function(percentage, message). It's called with 0 <= percentage <= 1. percentage == 0 indicates the start. percentage == 1 indicates the end.

挂接进编译器以提取进度信息。handler必须具备这样的函数签名function(percentage, message)。它会在0 <= percentage <= 1时被调用。percentage == 0表示开始。 percentage == 1表示结束。

RecordIdsPlugin()

Saves and restores module and chunk ids from records.

向记录/从记录,保存/恢复模块和 chunk 的 id

entry

Plugins, which add entry chunks to the compilation.

向 compilation 添加入口块的插件

SingleEntryPlugin(context, request, chunkName)

Adds a entry chunk on compilation. The chunk is named chunkName and contains only one module (plus dependencies). The module is resolved from request in context (absolute path).

在编译期添加一个入口块。该块以chunkName命名,且只包含一个模块(加上依赖)。这个模块根据context(绝对路径)的request解析

MultiEntryPlugin(context, requests, chunkName)

Adds a entry chunk on compilation. The chunk is named chunkName and contains a module for each item in the requests array (plus dependencies). Each item in requests is resolved in context (absolute path).

在编译过程添加一个入口块。该块以chunkName命名,包含一个含有requests数组中所有项的模块(加上依赖)。requests中的每一项都通过context(绝对路径)解析得到

PrefetchPlugin(context, request)

Prefetches request and dependencies to enables more parallel compilation. It doesn't create any chunk. The module is resolved from request in context (absolute path).

预取request和依赖模块以便开启更多并行的编译过程。它不会产生任何 chunk。该模块是根据context(绝对路径)的request解析的。

output

FunctionModulePlugin(context, options)

Each emitted module is wrapped in a function.

每个生成的模块都以一个函数包裹。

options are the output options.

options就是配置中的输出选项

If options.pathinfo is set, each module function is annotated with a comment containing the module identifier shortened to context (absolute path).

如果设置了options.pathinfo,每个模块函数都会以一份注释标注,内含相对于context(绝对路径)模块标识符

JsonpTemplatePlugin(options)

Chunks are wrapped into JSONP-calls. A loading algorithm is included in entry chunks. It loads chunks by adding a <script> tag.

chunk 被包装成 JSONP 回调。一个加载算法被包含进入口块,其通过添加一个<script>标签加载分块。

options are the output options. options 输出选项

options.jsonpFunction is the JSONP function. options.jsonpFunction JSONP函数

options.publicPath is uses as path for loading the chunks. options.publicPath 用来加载分块的路径。

options.chunkFilename is the filename under that chunks are expected. options.chunkFilename 目标块的文件名

node/NodeTemplatePlugin(options)

Chunks are wrapped into node.js modules exporting the bundled modules. The entry chunks loads chunks by requiring them.

分块被包装成Node.js的模块,并输出捆绑了的模块。入口块通过引用它们来加载分块。

options are the output options. options 输出选项

options.chunkFilename is the filename under that chunks are expected. options.chunkFilename 目标块的文件名

LibraryTemplatePlugin(name, target)

The entries chunks are decorated to form a library name of type type.

入口块以一个类型为type的库name包装。

webworker/WebWorkerTemplatePlugin(options)

Chunks are loaded by importScripts. Else it's similar to JsonpTemplatePlugin. 分块是由importScripts加载。否则它类似于JsonpTemplatePlugin

options are the output options. options 输出选项

EvalDevToolModulePlugin

Decorates the module template by wrapping each module in a eval annotated with // @sourceURL.

通过包装在一个以// @ sourceURL注明的eval方法来包装每个模块模板。

SourceMapDevToolPlugin(sourceMapFilename, sourceMappingURLComment, moduleFilenameTemplate, fallbackModuleFilenameTemplate)

Decorates the templates by generating a SourceMap for each chunk.

通过为每个 chunk 生成一个 SourceMap 来包装模板

sourceMapFilename the filename template of the SourceMap. [hash], [name], [id], [file] and [filebase] are replaced. If this argument is missing, the SourceMap will be inlined as DataUrl.

sourceMapFilename SourceMap 的文件名模板。[hash], [name], [id], [file][filebase]会被替换。如果此参数缺失,SourceMap 被内联为 DataUrl

NoHotModuleReplacementPlugin()

Defines module.hot as false to remove hot module replacement code.

定义module.hotfalse,以移除模块热替换的代码。

HotModuleReplacementPlugin(options)

Add support for hot module replacement. Decorates the templates to add runtime code. Adds module.hot API.

添加模块热替换的支持。包装模板来添加运行时代码。添加module.hot的API。

options.hotUpdateChunkFilename The filename for hot update chunks options.hotUpdateChunkFilename 热更新分块的文件名

options.hotUpdateMainFilename The filename for the hot update manifest options.hotUpdateMainFilename 热更新清单的文件名

options.hotUpdateFunction JSON function name for the hot update options.hotUpdateFunction 热更新的 JSONP 函数名

source

Plugins affecting the source code of modules.

影响模块的源代码的插件

APIPlugin

Make __webpack_public_path__, __webpack_require__, __webpack_modules__, __webpack_chunk_load__ accessible. Ensures that require.valueOf and require.onError are not processed by other plugins.

__webpack_public_path____webpack_require____webpack_modules____webpack_chunk_load__在模块中可访问。确保require.valueOfrequire.onError不被其他插件处理。

CompatibilityPlugin

Currently useless. Ensures compatibility with other module loaders.

目前没有用。确保与其他模块加载器的兼容性。

ConsolePlugin

Offers a pseudo console if it is not available.

如果console不可用,提供了一个伪console

ConstPlugin

Try to evaluate expressions in if(...) and replace it with true/false.

尝试计算if(...)中的表达式并以true/false替换。

ProvidePlugin(name, request)

If name is used in a module it is filled by a module loaded by require(<request>).

如果name在一个模块中使用,它将由一个通过require(<request>)加载的模块填充。

NodeStuffPlugin(options, context)

Provide stuff that is normally available in node.js modules.

提供在Node.js模块能正常使用的对象。

It also ensures that module is filled with some node.js stuff if you use it.

如果你使用了module,它还保证了module含有部分node.js的相关属性

RequireJsStuffPlugin

Provide stuff that is normally available in require.js.

提供在require.js中能正常使用的对象。

require[js].config is removed. require.version is 0.0.0. requirejs.onError is mapped to require.onError.

require[js].config被移除了。require.version0.0.0requirejs.onError 映射为 require.onError

node/NodeSourcePlugin(options)

This module adds stuff from node.js that is not available in non-node.js environments.

这个模块添加某些在 node.js 有而在其他非 node.js环境中没有的东西。

It adds polyfills for process, console, Buffer and global if used. It also binds the built in Node.js replacement modules.

如果使用了的话,它会对process, console, Bufferglobal对象添加 polyfill。它也绑定了Node.js内置的替换模块。

node/NodeTargetPlugin

The plugins should be used if you run the bundle in a node.js environment.

如果您在 Node.js 的环境中运行 bundle,插件应该被使用。

It ensures that native modules are loaded correctly even if bundled.

其保证了,即使经过打包,本地模块依然被正确加载。

dependencies/AMDPlugin(options)

Provides AMD-style define and require to modules. Also bind require.amd, define.amd and __webpack_amd_options__ to the options passed as parameter.

向模块提供 AMD-风格的 define and require。同时将require.amd, define.amd__webpack_amd_options__绑定给作为参数传入的options

dependencies/CommonJsPlugin

Provides CommonJs-style require to modules.

向模块提供CommonJS的风格require

dependencies/LabeledModulesPlugin

Provide labels require: and exports: to modules. 向模块提供标签特性require: and exports:

dependencies/RequireContextPlugin(modulesDirectories, extensions)

Provides require.context. The parameter modulesDirectories and extensions are used to find alternative requests for files. It's useful to provide the same arrays as you provide to the resolver.

提供 require.contextmodulesDirectoriesextensions参数是用来寻找额外的文件请求的。提供同样的与之前提供给解析器的数组会很有用。

dependencies/RequireEnsurePlugin

Provides require.ensure.

提供require.ensure

dependencies/RequireIncludePlugin

Provides require.include. 提供 require.include

DefinePlugin(definitions)

Define constants for identifier.

为标识符定义常量。

definitions is an object.

definitions是一个对象。

optimize

optimize/LimitChunkCountPlugin(options)

Merge chunks limit chunk count is lower than options.maxChunks.

合并的分块的限制数量需小于options.maxChunks

The overhead for each chunks is provided by options.chunkOverhead or defaults to 10000. Entry chunks sizes are multiplied by options.entryChunkMultiplicator (or 10).

每个块的开销是由options.chunkOverhead提供或默认为10000。入口块的大小由options.entryChunkMultiplicator(或者 10)倍乘

Chunks that reduce the total size the most are merged first. If multiple combinations are equal the minimal merged size wins.

最大限度降低总大小的块最先被合并。如果多个组合是相等,采用最小合并尺寸。

optimize/MergeDuplicateChunksPlugin

Chunks with the same modules are merged.

命名相同的分块被合并。

optimize/RemoveEmptyChunksPlugin

Modules that are included in every parent chunk are removed from the chunk.

被包含在父级分块的模块会从当前分块中移除

optimize/MinChunkSizePlugin(minChunkSize)

Merges chunks until each chunk has the minimum size of minChunkSize.

合并分块直到每个分块大小不小于minChunkSize

optimize/FlagIncludedChunksPlugin

Adds chunk ids of chunks which are included in the chunk. This eliminates unnecessary chunk loads.

增加被包括在所述块的分块的分块标识。这消除了不必要的分块加载。

optimize/UglifyJsPlugin(options)

Minimizes the chunks with uglify.js.

使用uglify.js压缩分块

options are uglifyjs options.

optionsuglify.js的选项。

optimize/OccurenceOrderPlugin(preferEntry)

Order the modules and chunks by occurrence. This saves space, because often referenced modules and chunks get smaller ids.

将模块与分块按出现顺序排序。这可以节省控件,因为经常引用的模块和分块会得到更小的id

preferEntry If true, references in entry chunks have higher priority

如果preferEntry为真,入口块中的引用优先级更高。

optimize/DedupePlugin

Deduplicates modules and adds runtime code.

删除重复的模块并增加运行时代码。

Clone this wiki locally