Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface LoaderContext

Hierarchy

  • LoaderContext
    • LoaderContext

Index

Properties

_compilation

_compilation: any

Hacky access to the Compilation object of webpack.

_compiler

_compiler: Compiler

Hacky access to the Compiler object of webpack.

_module

_module: any

Hacky access to the Module object being loaded.

callback

callback: loaderCallback

context

context: string

The directory of the module. Can be used as context for resolving other stuff. In the example: /abc because resource.js is in this directory

cssBlocks

cssBlocks: CssBlocksContext

Optional data

data: any

A data object shared between the pitch and the normal phase.

debug

debug: boolean

A boolean flag. It is set when in debug mode.

fs

fs: any

Access to the compilation's inputFileSystem property.

hot

hot: boolean

Flag if HMR is enabled

inputValue

inputValue: any

Passed from the last loader. If you would execute the input argument as module, consider reading this variable for a shortcut (for performance).

loaderIndex

loaderIndex: number

The index in the loaders array of the current loader. In the example: in loader1: 0, in loader2: 1

loaders

loaders: any[]

loaders = [{request: string, path: string, query: string, module: function}] An array of all the loaders. It is writeable in the pitch phase. 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] } ]

minimize

minimize: boolean

Should the result be minimized.

query

query: any

A string or any object. The query of the request for the current loader.

request

request: string

The resolved request string. In the example: "/abc/loader1.js?xyz!/abc/node_modules/loader2/index.js!/abc/resource.js?rrr"

resource

resource: string

The resource part of the request, including query. In the example: "/abc/resource.js?rrr"

resourcePath

resourcePath: string

The resource file. In the example: "/abc/resource.js"

resourceQuery

resourceQuery: string

The query of the resource. In the example: "?rrr"

sourceMap

sourceMap: boolean

Should a SourceMap be generated.

target

target: "web" | "webworker" | "async-node" | "node" | "electron-main" | "electron-renderer" | "node-webkit" | string

Target of compilation. Passed from configuration options. Example values: "web", "node"

value

value: any

Pass values to the next loader. If you know what your result exports if executed as module, set this value here (as a only element array).

version

version: string

Loader API version. Currently 2. This is useful for providing backwards compatibility. Using the version you can specify custom logic or fallbacks for breaking changes.

webpack

webpack: boolean

This boolean is set to true when this is compiled by webpack.

Loaders were originally designed to also work as Babel transforms. Therefore if you write a loader that works for both, you can use this property to know if there is access to additional loaderContext and webpack features.

Methods

addContextDependency

  • addContextDependency(directory: string): void
  • Add a directory as dependency of the loader result.

    Parameters

    • directory: string

    Returns void

addDependency

  • addDependency(file: string): 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.

    Parameters

    • file: string

    Returns void

async

  • async(): loaderCallback | undefined
  • Make this loader async.

    Returns loaderCallback | undefined

cacheable

  • cacheable(flag?: undefined | true | false): void
  • Make this loader result cacheable. By default it's not 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.

    Parameters

    • Optional flag: undefined | true | false

    Returns void

clearDependencies

  • clearDependencies(): void
  • Remove all dependencies of the loader result. Even initial dependencies and these of other loaders. Consider using pitch.

    Returns void

dependency

  • dependency(file: string): 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.

    Parameters

    • file: string

    Returns void

emitError

  • emitError(message: string | Error): void
  • Emit a error.

    Parameters

    • message: string | Error

    Returns void

emitFile

  • emitFile(name: string, content: Buffer | string, sourceMap: any): void
  • Emit a file. This is webpack-specific.

    Parameters

    • name: string
    • content: Buffer | string
    • sourceMap: any

    Returns void

emitWarning

  • emitWarning(message: string | Error): void
  • Emit a warning.

    Parameters

    • message: string | Error

    Returns void

exec

  • exec(code: string, filename: string): any
  • Execute some code fragment like a module.

    Don't use require(this.resourcePath), use this function to make loaders chainable!

    Parameters

    • code: string
    • filename: string

    Returns any

resolve

  • resolve(context: string, request: string, callback: function): any
  • Resolve a request like a require expression.

    Parameters

    • context: string
    • request: string
    • callback: function
        • (err: Error, result: string): void
        • Parameters

          • err: Error
          • result: string

          Returns void

    Returns any

resolveSync

  • resolveSync(context: string, request: string): string
  • Resolve a request like a require expression.

    Parameters

    • context: string
    • request: string

    Returns string

Generated using TypeDoc