提交学习笔记专用
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.

51 lines
1.7 KiB

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