| 1 | # loader-runner
|
|---|
| 2 |
|
|---|
| 3 | ```js
|
|---|
| 4 | import { runLoaders } from "loader-runner";
|
|---|
| 5 |
|
|---|
| 6 | runLoaders(
|
|---|
| 7 | {
|
|---|
| 8 | resource: "/abs/path/to/file.txt?query",
|
|---|
| 9 | // String: Absolute path to the resource (optionally including query string)
|
|---|
| 10 |
|
|---|
| 11 | loaders: ["/abs/path/to/loader.js?query"],
|
|---|
| 12 | // String[]: Absolute paths to the loaders (optionally including query string)
|
|---|
| 13 | // {loader, options}[]: Absolute paths to the loaders with options object
|
|---|
| 14 |
|
|---|
| 15 | context: { minimize: true },
|
|---|
| 16 | // Additional loader context which is used as base context
|
|---|
| 17 |
|
|---|
| 18 | processResource: (loaderContext, resourcePath, callback) => {
|
|---|
| 19 | // ...
|
|---|
| 20 | },
|
|---|
| 21 | // Optional: A function to process the resource
|
|---|
| 22 | // Must have signature function(context, path, function(err, buffer))
|
|---|
| 23 | // By default readResource is used and the resource is added a fileDependency
|
|---|
| 24 |
|
|---|
| 25 | readResource: fs.readFile.bind(fs),
|
|---|
| 26 | // Optional: A function to read the resource
|
|---|
| 27 | // Only used when 'processResource' is not provided
|
|---|
| 28 | // Must have signature function(path, function(err, buffer))
|
|---|
| 29 | // By default fs.readFile is used
|
|---|
| 30 | },
|
|---|
| 31 | (err, result) => {
|
|---|
| 32 | // err: Error?
|
|---|
| 33 | // result.result: [Buffer | String, SourceMap?, Meta?]
|
|---|
| 34 | // The result as an array matching the arguments passed by the final normal loader
|
|---|
| 35 | // (typically [content, sourceMap, meta])
|
|---|
| 36 | // only available when no error occurred
|
|---|
| 37 | // result.resourceBuffer: Buffer
|
|---|
| 38 | // The raw resource as Buffer (useful for SourceMaps)
|
|---|
| 39 | // only available when no error occurred
|
|---|
| 40 | // result.cacheable: Bool
|
|---|
| 41 | // Is the result cacheable or do it require reexecution?
|
|---|
| 42 | // result.fileDependencies: String[]
|
|---|
| 43 | // An array of paths (existing files) on which the result depends on
|
|---|
| 44 | // result.missingDependencies: String[]
|
|---|
| 45 | // An array of paths (not existing files) on which the result depends on
|
|---|
| 46 | // result.contextDependencies: String[]
|
|---|
| 47 | // An array of paths (directories) on which the result depends on
|
|---|
| 48 | }
|
|---|
| 49 | );
|
|---|
| 50 | ```
|
|---|
| 51 |
|
|---|
| 52 | More documentation following...
|
|---|