Compilation 对象
Compilation 对象
Compilation 对象提供了许多可用的方法和钩子。本页面将列出可用的方法和属性。
compilation 对象的方法
getStats
function
返回当前编译的 Stats 对象。
addModule
function (module, callback)
将模块添加到当前编译中。
参数:
module- 要添加的模块callback- 模块添加完成后的回调函数
getModule
function (module)
通过模块标识符从编译中获取模块。
参数:
module- 要获取的模块。编译会使用module.identifier()方法从模块中提取标识符。
findModule
function (module)
尝试通过模块标识符搜索模块。
参数:
module- 要搜索的模块。编译会使用module.identifier()方法从模块中提取标识符。
buildModule
function (module, optional, origin, dependencies)
构建给定的模块。
参数:
module- 要构建的模块。optional- 可选的标志。origin- 请求构建该模块的源模块。dependencies- 要构建模块的可选依赖项。
processModuleDependencies
function (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)
密封(seal)编译。
参数:
callback- 编译被密封后调用的函数。
unseal
function
取消密封(unseal)编译。
参数:
callback- 编译被取消密封后调用的函数。
reportDependencyErrorsAndWarnings
function (module, blocks)
将给定模块的错误和警告添加到编译的错误和警告中。
参数:
module- 要报告其错误和警告的模块。blocks- 要报告的一组依赖块。
addChunkInGroup
function (groupOptions, module, loc, request)
将模块添加到现有的 chunk group 中,或创建一个新的 chunk group。返回一个 chunkGroup。
参数:
groupOptions- chunk group 的选项。module- 引用该 chunk group 的模块。loc- 在模块内引用 chunk group 的位置。request- 引用 chunk group 时的请求。
addChunk
function (name)
创建并添加一个新的 chunk 到 compilation.chunks 中。返回该 chunk。
参数:
name- chunk 的名称。
assignDepth
function (module)
递归地为给定模块及其依赖块分配 depth。
参数:
module- 要分配深度的模块。
getDependencyReference
function (module, dependency)
返回从给定模块到依赖的引用。
参数:
module- 所涉及的模块。dependency- 要获取引用的依赖。
processDependenciesBlocksForChunkGroups
function (inputChunkGroups)
从 Module 图创建 Chunk 图。该过程分两个阶段完成。第一阶段:遍历模块图并在 chunkDependencies 中构建基本的 chunk 图。第二阶段:遍历基本 chunk 图的每条可能路径并跟踪可用的模块。在遍历过程中,processDependenciesBlocksForChunkGroups 将 chunk 相互连接,并将 Blocks 与 Chunks 连接。当某个 chunk 的所有模块都已可用时,它会停止遍历,并且不会连接不需要的 chunk。
参数:
inputChunkGroups- 要处理的 chunk group。
removeReasonsOfDependencyBlock
function (module, block)
移除模块与依赖块之间的关系。
参数:
module- 要移除关系的模块。block- 依赖块。
patchChunksAfterReasonRemoval
function (module, chunk)
在移除依赖原因后,修补模块与 chunk 之间的关联。由 removeReasonsOfDependencyBlock 自动调用。
参数:
module- 要修补关联的模块。chunk- 要修补关联的 chunk。
removeChunkFromDependencies
function (block, chunk)
在移除依赖原因后,从依赖块模块和 chunk 中移除给定的 chunk。由 removeReasonsOfDependencyBlock 自动调用。
参数:
block-Chunk的块关联。chunk- 要从依赖中移除的 chunk。
sortItemsWithChunkIds
function
summarizeDependencies
function
createHash
function
createModuleAssets
function
createChunkAssets
function
getPath
function (filename, data)
返回插值后的路径。
参数:
filename- 用于获取带有哈希的资源路径。data- 数据对象。
getPathWithInfo
function (filename, data)
返回插值后的路径和资源信息。
参数:
filename- 用于获取带有哈希的资源路径。data- 数据对象。
createChildCompiler
function (name, outputOptions, plugins)
允许在 webpack 内部运行另一个 webpack 实例,但作为具有不同设置和配置的子实例。它会从父级(或顶层 compiler)复制所有钩子和插件,并创建一个子 Compiler 实例。返回创建的 Compiler。
参数:
name- 子Compiler的名称。outputOptions- 输出选项对象。plugins- 将要应用的 webpack 插件。
checkConstraints
function
emitAsset
function (file, source, assetInfo = {})
参数:
file- 资源的文件名source- 资源的内容assetInfo- 附加的资源信息
updateAsset
function (file, newSourceOrFunction, assetInfoUpdateOrFunction)
参数:
file- 资源的文件名newSourceOrFunction- 新的资源内容,或将旧内容转换为新内容的函数assetInfoUpdateOrFunction- 新的资源信息,或将旧信息转换为新信息的函数
deleteAsset
function (file)
参数:
file- 资源的文件名
getAssets
function
返回当前编译下所有资源的数组。
getAsset
function (name)
参数:
name- 要返回的资源的名称
帮助我们改进文档
发现翻译问题或内容错误?请告诉我们。
