On this page

These types are not exported by webpack, but they are available to TypeScript consumers.

These properties are added by the HotModuleReplacementPlugin

Attributes

Custom values available in the loader context.

  • [index: {string}] any

Attributes
content:string
sourceMap:string | RawSourceMap
additionalData:AdditionalData
Returns:string | void | Buffer<ArrayBufferLike> | Promise<string | Buffer<ArrayBufferLike>>

Attributes
ident:string | null
loader:string
options:string | Record<string, any> | null
type:string | null

Attributes
default:RawLoaderDefinitionFunction<OptionsType, ContextAdditions> | LoaderDefinitionFunction<OptionsType, ContextAdditions>
pitch:PitchLoaderDefinitionFunction<OptionsType, ContextAdditions>
raw:false

These properties are added by the LoaderPlugin

importModule(request, options, callback): void
Attributes
request:string
callback:(err?: Error | null, exports?: any) => void
Returns:void
Attributes
request:string
Returns:Promise<any>
loadModule(request, callback): void
Attributes
request:string
callback:(err: Error | null, source?: string | Buffer<ArrayBufferLike>, sourceMap?: object | null, module?: Module) => void
Returns:void

Resolves the given request to a module, applies all configured loaders and calls back with the generated source, the sourceMap and the module instance (usually an instance of NormalModule). Use this function if you need to know the source code of another module to generate the result.


The properties are added by https://github.com/webpack/loader-runner

Attributes
callback:(err?: Error | null, content?: string | Buffer<ArrayBufferLike>, sourceMap?: string | RawSourceMap | null, additionalData?: AdditionalData) => void
context:string
The directory of the module. Can be used as context for resolving other stuff. eg '/workspaces/ts-loader/examples/vanilla/src'
currentRequest:string
data:any
environment:Environment
Tell what kind of ES-features may be used in the generated runtime-code. Example: arrowFunction: true
loaderIndex:number
The index in the loaders array of the current loader. In the example: in loader1: 0, in loader2: 1
loaders:{ data?: object; fragment: string; ident: string; normal?: Function; normalExecuted: boolean; options?: string | object; path: string; pitch?: Function; pitchExecuted: boolean; query: string; raw?: boolean; request: string; type?: "module" | "commonjs" }[]
An array of all the loaders. It is writeable in the pitch phase. loaders = [ request: string, path: string, query: string, module: function ] In the example: [ request: "/abc/loader1.js?xyz", path: "/abc/loader1.js", query: "?xyz", module: [Function] , request: "/abc/node_modules/loader2/index.js", path: "/abc/node_modules/loader2/index.js", query: "", module: [Function] ]
previousRequest:string
query:string | OptionsType
remainingRequest:string
request:string
resource:string
The resource inclusive query and fragment. Example: "/abc/resource.js?query#frag"
resourceFragment:string
The resource fragment. Example: "#frag"
resourcePath:string
The resource path. In the example: "/abc/resource.js"
resourceQuery:string
The resource query string. Example: "?query"
target:string
Target of compilation. Example: "web"
addContextDependency(context): void
Attributes
context:string
Returns:void

Add a directory as dependency of the loader result.

addDependency(file): void
Attributes
file:string
Returns:void

Adds a file as dependency of the loader result in order to make them watchable. For example, html-loader uses this technique as it finds src and src-set attributes. Then, it sets the url's for those attributes as dependencies of the html file that is parsed.

addMissingDependency(context): void
Attributes
context:string
Returns:void
async(): (err?: Error | null, content?: string | Buffer<ArrayBufferLike>, sourceMap?: string | RawSourceMap | null, additionalData?: AdditionalData) => void
Returns:(err?: Error | null, content?: string | Buffer<ArrayBufferLike>, sourceMap?: string | RawSourceMap | null, additionalData?: AdditionalData) => void

Make this loader async.

cacheable(flag?): void
Attributes
flag:boolean
Returns:void

Make this loader result cacheable. By default it's cacheable. A cacheable loader must have a deterministic result, when inputs and dependencies haven't changed. This means the loader shouldn't have other dependencies than specified with this.addDependency. Most loaders are deterministic and cacheable.

clearDependencies(): void
Returns:void

Remove all dependencies of the loader result. Even initial dependencies and these of other loaders.

dependency(file): void
Attributes
file:string
Returns:void

alias of addDependency Adds a file as dependency of the loader result in order to make them watchable. For example, html-loader uses this technique as it finds src and src-set attributes. Then, it sets the url's for those attributes as dependencies of the html file that is parsed.

getContextDependencies(): string[]
Returns:string[]
getDependencies(): string[]
Returns:string[]
getMissingDependencies(): string[]
Returns:string[]

These properties are added by the NormalModule

Attributes
_compilation:Compilation
_compiler:Compiler
_module:NormalModule
hashDigest:string
hashDigestLength:number
hashFunction:HashFunction
hashSalt:string
mode:"development" | "none" | "production"
rootContext:string
sourceMap:boolean
utils:{ absolutify: (context: string, request: string) => string; contextify: (context: string, request: string) => string; createHash: (algorithm?: string | typeof Hash) => Hash }
version:number
webpack:boolean
addBuildDependency(dep): void
Attributes
dep:string
Returns:void
emitError(error): void
Attributes
error:string | Error
Returns:void

Emits an error for this module. The error will be displayed to the user and typically causes the compilation to fail.

emitFile(name, content, sourceMap?, assetInfo?): void
Attributes
name:string
content:string | Buffer<ArrayBufferLike>
sourceMap:string
assetInfo:AssetInfo
Returns:void

Emits a new file (asset) to the compilation output directory. This allows loaders to generate additional files alongside the main module output.

emitWarning(warning): void
Attributes
warning:string | Error
Returns:void

Emits a warning for this module. The warning will be displayed to the user during compilation.

getLogger(name?): WebpackLogger
Attributes
name:string

Gets a logger instance scoped to this loader and module. Useful for emitting debug or compilation information in a structured way.

getOptions(): void
Returns:OptionsType

Extracts and parses the options of the current loader. Parses string options as JSON or a query string.

Attributes
schema:Schema
Returns:OptionsType

Extracts and parses the options of the current loader. Parses string options as JSON or a query string, and optionally validates them against a provided schema.

getResolve(options?): { (context: string, request: string, callback: (err: ErrorWithDetail | null, res?: string | false, req?: ResolveRequest) => void): void; (context: string, request: string): Promise<string> }
Attributes
Returns:{ (context: string, request: string, callback: (err: ErrorWithDetail | null, res?: string | false, req?: ResolveRequest) => void): void; (context: string, request: string): Promise<string> }

Creates a resolve function with specific options. The returned function can be used as a Promise-based resolver or a callback-based resolver.

resolve(context, request, callback): void
Attributes
context:string
request:string
callback:(err: ErrorWithDetail | null, res?: string | false, req?: ResolveRequest) => void
Returns:void

Resolves a module request (e.g., a relative path or module name) to an absolute file path. It uses Webpack's internal resolver, taking into account configured aliases and extensions.


Attributes
remainingRequest:string
previousRequest:string
data:object
Returns:string | void | Buffer<ArrayBufferLike> | Promise<string | Buffer<ArrayBufferLike>>

Attributes
content:Buffer
sourceMap:string | RawSourceMap
additionalData:AdditionalData
Returns:string | void | Buffer<ArrayBufferLike> | Promise<string | Buffer<ArrayBufferLike>>


Type:LoaderDefinitionFunction<OptionsType, ContextAdditions> & { pitch?: PitchLoaderDefinitionFunction<OptionsType, ContextAdditions>; raw?: false }
Attributes
pitch:PitchLoaderDefinitionFunction<OptionsType, ContextAdditions>
raw:false

Type:RawLoaderDefinitionFunction<OptionsType, ContextAdditions> & { pitch?: PitchLoaderDefinitionFunction<OptionsType, ContextAdditions>; raw: true }
Attributes
pitch:PitchLoaderDefinitionFunction<OptionsType, ContextAdditions>
raw:true