1 |
3a515b92
|
cagy
|
# loader-runner
|
2 |
|
|
|
3 |
|
|
``` js
|
4 |
|
|
import { runLoaders } from "loader-runner";
|
5 |
|
|
|
6 |
|
|
runLoaders({
|
7 |
|
|
resource: "/abs/path/to/file.txt?query",
|
8 |
|
|
// String: Absolute path to the resource (optionally including query string)
|
9 |
|
|
|
10 |
|
|
loaders: ["/abs/path/to/loader.js?query"],
|
11 |
|
|
// String[]: Absolute paths to the loaders (optionally including query string)
|
12 |
|
|
// {loader, options}[]: Absolute paths to the loaders with options object
|
13 |
|
|
|
14 |
|
|
context: { minimize: true },
|
15 |
|
|
// Additional loader context which is used as base context
|
16 |
|
|
|
17 |
|
|
readResource: fs.readFile.bind(fs)
|
18 |
|
|
// A function to read the resource
|
19 |
|
|
// Must have signature function(path, function(err, buffer))
|
20 |
|
|
|
21 |
|
|
}, function(err, result) {
|
22 |
|
|
// err: Error?
|
23 |
|
|
|
24 |
|
|
// result.result: Buffer | String
|
25 |
|
|
// The result
|
26 |
|
|
|
27 |
|
|
// result.resourceBuffer: Buffer
|
28 |
|
|
// The raw resource as Buffer (useful for SourceMaps)
|
29 |
|
|
|
30 |
|
|
// result.cacheable: Bool
|
31 |
|
|
// Is the result cacheable or do it require reexecution?
|
32 |
|
|
|
33 |
|
|
// result.fileDependencies: String[]
|
34 |
|
|
// An array of paths (files) on which the result depends on
|
35 |
|
|
|
36 |
|
|
// result.contextDependencies: String[]
|
37 |
|
|
// An array of paths (directories) on which the result depends on
|
38 |
|
|
})
|
39 |
|
|
```
|
40 |
|
|
|
41 |
|
|
More documentation following...
|