On this page

class webpack.Module extends DependenciesBlock
new Module(type, context?, layer?): Module
Attributes
type:string
the module type, when deserializing the type is not known and is an empty string
context:string | null
an optional context
layer:string | null
an optional layer in which the module is
Returns:Module

Creates an instance of Module.

Attributes
buildInfo:BuildInfo
buildMeta:BuildMeta
chunksIterable:Iterable<Chunk>
codeGenerationDependencies:Dependency[]
context:string | null
debugId:number
dependencies:Dependency[]
depth:number | null
Updates the depth using the provided value.
errors:any
exportsArgument:string
Gets exports argument.
factoryMeta:FactoryMeta
hasEqualsChunks:any
hash:string
Returns the hash of the module.
id:string | number | null
Updates the module id using the provided value.
index:number | null
Updates the pre-order index using the provided value.
index2:number | null
Updates the post-order index using the provided value.
issuer:Module | null
Updates the issuer using the provided value.
isUsed:any
layer:string | null
moduleArgument:string
Gets module argument.
needId:boolean
optimizationBailout:(string | ((requestShortener: RequestShortener) => string))[]
Gets optimization bailout.
optional:boolean
presentationalDependencies:Dependency[]
renderedHash:string
Returns the rendered hash of the module.
resolveOptions:ResolveOptions
type:string
used:any
usedExports:boolean | SortableSet<string> | null
useSimpleSourceMap:boolean
useSourceMap:boolean
warnings:any
addBlock(block): void
Attributes

Adds a DependencyBlock to DependencyBlock relationship. This is used for when a Module has a AsyncDependencyBlock tie (for code-splitting)


addCacheDependencies(fileDependencies, contextDependencies, missingDependencies, buildDependencies): void
Attributes
fileDependencies:LazySet<string>
set where file dependencies are added to
contextDependencies:LazySet<string>
set where context dependencies are added to
missingDependencies:LazySet<string>
set where missing dependencies are added to
buildDependencies:LazySet<string>
set where build dependencies are added to
Returns:void

Adds the provided file dependencies to the module.


addChunk(chunk): boolean
Attributes
chunk:Chunk
the chunk
Returns:boolean
true, when the module was added

Adds the provided chunk to the module.


addCodeGenerationDependency(codeGenerationDependency): void
Attributes
codeGenerationDependency:Dependency
dependency being tied to module. This is a Dependency where the code generation result of the referenced module is needed during code generation. The Dependency should also be added to normal dependencies via addDependency.
Returns:void

Adds code generation dependency.


addDependency(dependency): void
Attributes
dependency:Dependency
Returns:void

Adds the provided dependency to the dependencies block.


addError(error): void
Attributes
error:Error
the error
Returns:void

Adds the provided error to the module.


addPresentationalDependency(presentationalDependency): void
Attributes
presentationalDependency:Dependency
dependency being tied to module. This is a Dependency without edge in the module graph. It's only for presentation.
Returns:void

Adds presentational dependency.


addWarning(warning): void
Attributes
warning:Error
the warning
Returns:void

Adds the provided warning to the module.


build(options, compilation, resolver, fs, callback): void
Attributes
compilation:Compilation
the compilation
the resolver
the file system
callback:(err?: WebpackError) => void
callback function
Returns:void

Builds the module using the provided compilation context.


chunkCondition(chunk, compilation): boolean
Attributes
chunk:Chunk
the chunk which condition should be checked
compilation:Compilation
the compilation
Returns:boolean
true if the module can be placed in the chunk

Returns true if the module can be placed in the chunk.


cleanupForCache(): void
Returns:void

Assuming this module is in the cache. Remove internal references to allow freeing some memory.


clearDependenciesAndBlocks(): void
Returns:void

Clear dependencies and blocks.


clearWarningsAndErrors(): void
Returns:void

removes all warnings and errors


codeGeneration(context): CodeGenerationResult
Attributes
context for code generation
result

Generates code and runtime requirements for this module.


deserialize(objectDeserializerContext): void
Attributes
objectDeserializerContext:ObjectDeserializerContext
Returns:void

Restores this instance from the provided deserializer context.


getChunks(): Chunk[]
Returns:Chunk[]
chunks

getConcatenationBailoutReason(context): string | undefined
Attributes
Returns:string | undefined
reason why this module can't be concatenated, undefined when it can be concatenated

Returns the reason this module cannot be concatenated, when one exists.


getErrors(): Error[] | undefined
Returns:Error[] | undefined
list of errors if any

Returns list of errors if any.


getExportsType(moduleGraph, strict?): ExportsType
Attributes
moduleGraph:ModuleGraph
the module graph
strict:boolean
the importing module is strict
Returns:ExportsType
export type "namespace": Exports is already a namespace object. namespace = exports. "dynamic": Check at runtime if __esModule is set. When set: namespace = ...exports, default: exports . When not set: namespace = default: exports . "default-only": Provide a namespace object with only default export. namespace = default: exports "default-with-named": Provide a namespace object with named and default export. namespace = ...exports, default: exports

Returns export type.


getNumberOfChunks(): number
Returns:number
number of chunks

getNumberOfErrors(): number
Returns:number
number of errors

Gets number of errors.


getNumberOfWarnings(): number
Returns:number
number of warnings

Gets number of warnings.


getRootBlock(): DependenciesBlock

getSideEffectsConnectionState(moduleGraph): ConnectionState
Attributes
moduleGraph:ModuleGraph
the module graph
how this module should be connected to referencing modules when consumed for side-effects only

Gets side effects connection state.


getSourceBasicTypes(): ReadonlySet<string>
Stability: 0Deprecated: In webpack 6, call getSourceBasicTypes() directly on the module instance instead of using this static method.
Returns:ReadonlySet<string>
the source types of the module

Gets source basic types.


getSourceTypes(): ReadonlySet<string>
Returns:ReadonlySet<string>
types available (do not mutate)

Returns the source types this module can generate.


getUnsafeCacheData(): UnsafeCacheData
cached data

Module should be unsafe cached. Get data that's needed for that. This data will be passed to restoreFromUnsafeCache later.


getWarnings(): Error[] | undefined
Returns:Error[] | undefined
list of warnings if any

Returns list of warnings if any.


hasChunkCondition(): boolean
Returns:boolean

hasReasonForChunk(chunk, moduleGraph, chunkGraph): boolean
Attributes
chunk:Chunk
a chunk
moduleGraph:ModuleGraph
the module graph
chunkGraph:ChunkGraph
the chunk graph
Returns:boolean
true, if the module has any reason why "chunk" should be included

Checks whether this module contains the chunk.


hasReasons(moduleGraph, runtime): boolean
Attributes
moduleGraph:ModuleGraph
the module graph
runtime:RuntimeSpec
the runtime
Returns:boolean
true if at least one other module depends on this module

Checks whether this module contains the module graph.


identifier(): string
Returns:string
a unique identifier of the module

Returns the unique identifier used to reference this module.


invalidateBuild(): void
Returns:void

Invalidates the cached state associated with this value.


isAccessibleInChunk(chunkGraph, chunk, ignoreChunk?): boolean
Attributes
chunkGraph:ChunkGraph
the chunk graph
chunk:Chunk
a chunk
ignoreChunk:Chunk
chunk to be ignored
Returns:boolean
true, if the module is accessible from "chunk" when ignoring "ignoreChunk"

Checks whether this module is accessible in chunk.


isAccessibleInChunkGroup(chunkGraph, chunkGroup, ignoreChunk?): boolean
Attributes
chunkGraph:ChunkGraph
the chunk graph
chunkGroup:ChunkGroup
a chunk group
ignoreChunk:Chunk
chunk to be ignored
Returns:boolean
true, if the module is accessible from "chunkGroup" when ignoring "ignoreChunk"

Checks whether this module is accessible in chunk group.


isEntryModule(): boolean
Returns:boolean
true when is entry module, otherwise false

isInChunk(chunk): boolean
Attributes
chunk:Chunk
the chunk
Returns:boolean
true, when the module is in the chunk

Checks whether this module is in the provided chunk.


isOptional(moduleGraph): boolean
Attributes
moduleGraph:ModuleGraph
the module graph
Returns:boolean
true, if the module is optional

Checks whether this module is optional.


isProvided(exportName): boolean | null
Attributes
exportName:string
a name of an export
Returns:boolean | null
true, if the export is provided why the module. null, if it's unknown. false, if it's not provided.

Checks whether this module provides the specified export.


libIdent(options): string | null
Attributes
options
Returns:string | null
an identifier for library inclusion

Gets the library identifier.


nameForCondition(): string | null
Returns:string | null
absolute path which should be used for condition matching (usually the resource path)

Returns the path used when matching this module against rule conditions.


needBuild(context, callback): void
Attributes
context info
callback:(err?: WebpackError | null, needBuild?: boolean) => void
callback function, returns true, if the module needs a rebuild
Returns:void

Checks whether the module needs to be rebuilt for the current build state.


needRebuild(fileTimestamps, contextTimestamps): boolean
Stability: 0Deprecated: Use needBuild instead
Attributes
fileTimestamps:Map<string, number | null>
timestamps of files
contextTimestamps:Map<string, number | null>
timestamps of directories
Returns:boolean
true, if the module needs a rebuild

Checks whether it needs rebuild.


originalSource(): Source | null
Returns:Source | null
the original source for the module before webpack transformation

Gets the original source.


readableIdentifier(requestShortener): string
Attributes
requestShortener:RequestShortener
the request shortener
Returns:string
a user readable identifier of the module

Returns a human-readable identifier for this module.


removeChunk(chunk): void
Attributes
chunk:Chunk
the chunk
Returns:void

Removes the provided chunk from the module.


removeDependency(dependency): void
Attributes
dependency:Dependency
Returns:void

Removes dependency.


serialize(objectSerializerContext): void
Attributes
objectSerializerContext:ObjectSerializerContext
Returns:void

Serializes this instance into the provided serializer context.


size(type?): number
Attributes
type:string
the source type for which the size should be estimated
Returns:number
the estimated size of the module (must be non-zero)

Returns the estimated size for the requested source type.


source(dependencyTemplates, runtimeTemplate, type?): Source
Stability: 0Deprecated: Use codeGeneration() instead
Attributes
dependencyTemplates:DependencyTemplates
the dependency templates
runtimeTemplate:RuntimeTemplate
the runtime template
type:string
the type of source that should be generated
Returns:Source
generated source

Returns generated source.


updateCacheModule(module): void
Attributes
module:Module
fresh module
Returns:void

Assuming this module is in the cache. Update the (cached) module with the fresh module from the factory. Usually updates internal references and properties.


updateHash(hash, context): void
Attributes
hash:Hash
the hash used to track dependencies
Returns:void

Updates the hash with the data contributed by this instance.


Stability: 0Deprecated: In webpack 6, call getSourceBasicTypes() directly on the module instance instead of using this static method.
Attributes
module:Module
the module
Returns:ReadonlySet<string>
the source types of the module

Gets source basic types.