You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.7 KiB

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