编译对象

Compilation 对象有许多可用的方法和钩子。在本页中,我们将列出可用的方法和属性。

compilation 对象方法

getStats

函数

返回当前编译的 Stats 对象。

addModule

函数 (module, callback)

将模块添加到当前编译中。

参数

  • module - 要添加的模块
  • callback - 模块添加后的回调函数

getModule

函数 (module)

通过其标识符从编译中获取模块。

参数

  • module - 要获取的模块。编译使用 module.identifier() 方法从模块中提取标识符。

findModule

函数 (module)

尝试通过其标识符搜索模块。

参数

  • module - 要搜索的模块。编译使用 module.identifier() 方法从模块中提取标识符。

buildModule

函数 (module, optional, origin, dependencies)

构建给定的模块。

参数

  • module - 要构建的模块。
  • optional - 可选标志。
  • origin - 请求此模块构建的源模块。
  • dependencies - 模块构建的可选依赖项。

processModuleDependencies

函数 (module, callback)

处理给定的模块依赖项。

参数

  • module - 要处理依赖项的模块。
  • callback - 当模块的依赖项处理完毕时要调用的函数。

addEntry

function (context, entry, name, callback)

向编译添加一个条目。

参数

  • context - 条目的上下文路径。
  • entry - 条目依赖项。
  • name - 条目的名称。
  • callback - 当 addEntry 完成时要调用的函数。

rebuildModule

function (module, thisCallback)

触发模块的重新构建。

参数

  • module - 要重建的模块。
  • thisCallback - 当模块完成重建时要调用的函数。

finish

function (callback)

完成编译并调用给定的回调函数。

参数

  • callback - 当编译完成时要调用的函数。

seal

function (callback)

密封编译。

参数

  • callback - 当编译完成密封时要调用的函数。

unseal

函数

解除编译的密封。

参数

  • callback - 当编译完成解除密封时要调用的函数。

reportDependencyErrorsAndWarnings

function (module, blocks)

将给定模块的错误和警告添加到编译错误和警告中。

参数

  • module - 要报告错误和警告的模块。
  • blocks - 要报告的依赖项块集。

addChunkInGroup

function (groupOptions, module, loc, request)

将模块添加到现有的块组或创建一个新的块组。返回一个 chunkGroup

参数

  • groupOptions - 块组选项。
  • module - 引用块组的模块。
  • loc - 引用块组的位置(在模块内部)。
  • request - 引用块组的请求。

addChunk

function (name)

创建并向 compilation.chunks 添加一个新的块。返回该 chunk

参数

  • name - 块的名称。

assignDepth

函数 (module)

递归地将 depth 分配给给定模块及其依赖块。

参数

  • module - 要分配深度的模块。

getDependencyReference

function (module, dependency)

返回给定模块对依赖项的引用。

参数

  • module - 相关的模块。
  • dependency - 要获取引用的依赖项。

processDependenciesBlocksForChunkGroups

function (inputChunkGroups)

Module 图创建 Chunk 图。该过程分两个阶段进行。第一阶段:遍历模块图并在 chunkDependencies 中构建一个基本的块图。第二阶段:遍历基本块图中的每种可能路径并跟踪可用模块。在遍历过程中,processDependenciesBlocksForChunkGroups 将块彼此连接,并将 BlocksChunks 连接。当块的所有模块都已可用时,它将停止遍历,并且不会连接不需要的块。

参数

  • inputChunkGroups - 被处理的块组。

removeReasonsOfDependencyBlock

function (module, block)

删除模块与依赖块之间的关系。

参数

  • module - 要删除关系的模块。
  • block - 依赖块。

patchChunksAfterReasonRemoval

function (module, chunk)

在移除依赖原因后,修补模块和块的绑定。由 `removeReasonsOfDependencyBlock` 自动调用。

参数

  • module - 要修补绑定的模块。
  • chunk - 要修补绑定的块。

removeChunkFromDependencies

function (block, chunk)

在移除依赖原因后,从依赖块模块和块中移除给定的块。由 `removeReasonsOfDependencyBlock` 自动调用。

参数

  • block - Chunk 的块绑定。
  • chunk - 要从依赖项中移除的块。

sortItemsWithChunkIds

函数

summarizeDependencies

函数

createHash

函数

createModuleAssets

函数

createChunkAssets

函数

getPath

function (filename, data)

返回插值的路径。

参数

  • filename - 用于获取带有哈希的资产路径。
  • data - 数据对象。

getPathWithInfo

function (filename, data)

返回插值的路径和资产信息。

参数

  • filename - 用于获取带有哈希的资产路径。
  • data - 数据对象。

createChildCompiler

function (name, outputOptions, plugins)

允许在 webpack 内部运行另一个 webpack 实例。但是,作为具有不同设置和配置的子实例。它复制来自父级(或顶级编译器)的所有钩子和插件,并创建一个子 `Compiler` 实例。返回创建的 `Compiler`。

参数

  • name - 子 `Compiler` 的名称。
  • outputOptions - 输出选项对象。
  • plugins - 将要应用的 webpack 插件。

checkConstraints

函数

emitAsset

function (file, source, assetInfo = {})

参数

  • file - 资源文件的名称
  • source - 资源文件的来源
  • assetInfo - 额外的资源信息

updateAsset

function (file, newSourceOrFunction, assetInfoUpdateOrFunction)

参数

  • file - 资源文件的名称
  • newSourceOrFunction - 新的资源来源或将旧资源转换为新资源的函数
  • assetInfoUpdateOrFunction - 新的资源信息或将旧资源信息转换为新资源信息的函数

deleteAsset

function (file)

参数

  • file - 资源文件的名称

getAssets

函数

返回当前编译下的所有资源的数组。

getAsset

function (name)

参数

  • name - 要返回的资源的名称

4 位贡献者

EugeneHlushkowizardofhogwartsjamesgeorge007snitin315