webpack@4.46.0 辅助信息

2022-11-16 14:34:28 浏览数 (1)

compilation.seal中逻辑梳理,目的是找到有效主流程逻辑

未用到:表示内置没有注册的插件

seal: 钩子和调用

可能的注册和功能

hooks.seal

WarnCaseSersitiveModulesPlugin

hooks.optimizeDependenciesBasic, hooks.optimizeDependencies, hooks.optimizeDependenciesAdvanced

1. 未用到 2. FlagAllModulesAsUsedPlugin、FlagDependencyUsagePlugin、SideEffectsFlagPlugin (普通模式下没有用到 - 非必须- 优化策略应该) 3. 未用到

hooks.afterOptimizeDependencies

未用到

hooks.beforeChunks

未用到

构造初始ChunkGroupsh和EntryPoints

_preparedEntrypoints new EntryPoint()等

buildChunkGraph

由module-graph 初步构造 chunk-graph

sortModules()

hooks.afterChunks

WebAssemblyModulesPlugin

hooks.optimize

AggressiveSplittingPlugin

hooks.optimizeModulesBasic, hooks.optimizeModules, hooks.optimizeModulesAdvanced

1. 未用到 ,2. 未用到 , 3. 未用到

hooks.afterOptimizeModules

未用到

hooks.optimizeChunksBasic, hooks.optimizeChunks, hooks.optimizeChunksAdvanced

1. EnsureChunkConditionsPlugin、MergeDuplicateChunksPlugin、RemoveEmptyChunksPlugin、RemoveParentModulesPlugin 2. 未用到 3. RemoveEmptyChunksPlugin、AggressiveMergingPlugin、AggressiveSplittingPlugin、LimitChunkCountPlugin、MinChunkSizePlugin、RuntimeChunkPlugin、 SplitChunksPlugin

hooks.afterOptimizeChunks

FlagInitialModulesAsUsedPlugin

hooks.optimizeTree

未用到

hooks.optimizeTree 回调中的逻辑

标题

hooks.afterOptimizeTree

未用到: 表示webpack内部没有任何订阅

hooks.optimizeChunkModulesBasic、hooks.optimizeChunkModules、hooks.optimizeChunkModulesAdvanced

1. 未用到 2. ModuleConcatenationPlugin 3. 未用到

hooks.afterOptimizeChunkModules

未用到

hooks.reviveModules

compilation.hooks.reviveModules.tap( "RecordIdsPlugin",

hooks.optimizeModuleOrder

OccurrenceOrderPlugin OccurrenceOrderModuleIdsPlugin 普通模式下未用到

hooks.advancedOptimizeModuleOrder

未用到

hooks.beforeModuleIds

未用到

hooks.moduleIds

未用到 ChunkModuleIdRangePlugin

applyModuleIds()

hooks.optimizeModuleIds

未用到

hooks.afterOptimizeModuleIds

未用到

sortItemsWithModuleIds()

hooks.reviveChunks

RecordIdsPlugin

hooks.optimizeChunkOrder

NaturalChunkOrderPlugin 有用到 OccurrenceOrderPlugin OccurrenceOrderModuleIdsPlugin

hooks.beforeChunkIds

NamedChunksPlugin

applyChunkIds()

hooks.optimizeChunkIds

FlagIncludedChunksPlugin

hooks.afterOptimizeChunkIds

未用到

sortItemsWithChunkIds()

hooks.beforeHash

未用到

createHash()

1. … 2. JavascriptModulesPlugin.hooks.contentHash

hooks.afterHash

HotModuleReplacementPlugin

hooks.beforeModuleAssets

未用到

createModuleAssets()

NormalModule提供的loaderContext有emitFile,loader可以通过该接口将资源输出,此时并没有真正的输出文件,只是记录到 module.buildInfo.assets 中 这里的逻辑就是遍历所有的模块,将每个模块在loader阶段输出的文件添加到(调用compilation.emitAsset())compilation.assets中,统一走compilation的文件输出 file-loader中就有用到该emitFile接口,然后会进入 createModuleAssets() 中…

hooks.shouldGenerateChunkAssets、hooks.beforeChunkAssets

HotModuleReplacementPlugin shouldGenerateChunkAssets

createChunkAssets()

生成Chunk内容 保存到 compilation.assets中

hooks.additionalChunkAssets

HotModuleReplacementPlugin

summarizeDependencies()

hooks.additionalAssets

该钩子的回调中的钩子 hooks.optimizeChunkAssets - BannerPlugin hooks.afterOptimizeChunkAssets - SourceMapDevToolPlugin hooks.optimizeAssets - 无 hooks.afterOptimizeAssets - 无 hooks.needAdditionalSeal - AggressiveSplittingPlugin hooks.afterSeal - 无

所有插件??

WebpackOptionsApply中涉及的插件

插件

条件

备注

FetchCompileWasmTemplatePlugin

options.target = 'web

LoaderTargetPlugin

options.target = 'web

给loaderContext设置target

LibraryTemplatePlugin

output.library

ExternalsPlugin

externals

EvalSourceMapDevToolPlugin

SourceMapDevToolPlugin

EvalDevToolModulePlugin

devtool.includes("eval")

SizeLimitsPlugin

performance

NodeStuffPlugin

options.node !== false

parser相关;node相关忽略

WebAssemblyModulesPlugin

y

RecordIdsPlugin

y

WarnCaseSensitiveModulesPlugin

y

LoaderPlugin

y

关注

EnsureChunkConditionsPlugin

y

hooks.optimizeChunksBasic、optimizeExtractedChunksBasic

NodeSourcePlugin

options.target = 'web

parser相关,作用是?

EntryOptionPlugin

y

compiler.hooks.entryOption.call(options.context, options.entry);---

UseStrictPlugin

y

parser相关;use strict

CompatibilityPlugin

y

parser相关;支持 Browserify风格的require(file, opts)

RequireIncludePlugin

y

parser相关;RequireIncludeDependencyParserPlugin; webpack提供的require.include

RequireEnsurePlugin

y

parser相关;RequireEnsureDependenciesBlockParserPlugin; webpack提供的require.ensure

RequireContextPlugin

y

parser相关;RequireContextDependencyParserPlugin; webpack提供require.context---

SystemPlugin

y

parser相关;关注 模块定义系统;libraryTarget: 'system'

ImportPlugin

y

parser相关;ImportParserPlugin;import()

HarmonyModulesPlugin

y

parser相关,HarmonyDetectionParserPlugin、HarmonyImportDependencyParserPlugin、HarmonyExportDependencyParserPlugin、HarmonyTopLevelThisParserPlugin;es6规范

AMDPlugin

RequireJsStuffPlugin

options.amd !== false

CommonJsPlugin

y

parser相关;RequireResolveDependencyParserPlugin、CommonJsRequireDependencyParserPlugin;commonjs简写规范(cjs)

CommonJsStuffPlugin

y

parser相关;cjs规范?;模块变量 :module.loaded、module.id等等

APIPlugin

y

parser相关;模块变量 webpack_require、__webpack_public_path__等

JsonModulesPlugin

y

createParser & creatGengerator

JavascriptModulesPlugin

y

代码生成;

FunctionModulePlugin

options.target = 'web

代码生成;FunctionModuleTemplatePlugin

JsonpTemplatePlugin

options.target = 'web

代码生成 ;JsonpMainTemplatePlugin、JsonpChunkTemplatePlugin

TemplatedPathPlugin

y

模板路径❓

optimization相关的插件

插件

条件

备注

RemoveParentModulesPlugin

optimization.removeAvailableModules

RemoveEmptyChunksPlugin

optimization.removeEmptyChunks

MergeDuplicateChunksPlugin

optimization.mergeDuplicateChunks

FlagIncludedChunksPlugin

optimization.flagIncludedChunks

SideEffectsFlagPlugin

optimization.sideEffects

FlagDependencyExportsPlugin

optimization.providedExports

FlagDependencyUsagePlugin

optimization.usedExports

ModuleConcatenationPlugin

optimization.concatenateModules

SplitChunksPlugin

optimization.splitChunks

RuntimeChunkPlugin

optimization.runtimeChunk

NoEmitOnErrorsPlugin

optimization.noEmitOnErrors

WasmFinalizeExportsPlugin

optimization.checkWasmTypes

HashedModuleIdsPlugin

moduleIds="hashed"

OccurrenceModuleOrderPlugin

optimization.occurrenceOrder => moduleIds="size"

{prioritiseInitial: true}

NamedModulesPlugin

optimization.namedModules => moduleIds="named"

OccurrenceModuleOrderPlugin

moduleIds"total-size"

{prioritiseInitial: false}

NaturalChunkOrderPlugin

chunkIds="natural"

OccurrenceChunkOrderPlugin && NamedChunksPlugin

chunkIds="named"

OccurrenceChunkOrderPlugin

chunkIds="size"

{prioritiseInitial: true}

OccurrenceChunkOrderPlugin

chunkIds="total-size"

{prioritiseInitial: false}

DefinePlugin

nodeEnv

minimizer.call/apply

minimizer in minimizer

0 人点赞