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.

35 lines
831 B

4 years ago
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. module.exports = class UseFilePlugin {
  7. constructor(source, filename, target) {
  8. this.source = source;
  9. this.filename = filename;
  10. this.target = target;
  11. }
  12. apply(resolver) {
  13. const target = resolver.ensureHook(this.target);
  14. resolver
  15. .getHook(this.source)
  16. .tapAsync("UseFilePlugin", (request, resolveContext, callback) => {
  17. const filePath = resolver.join(request.path, this.filename);
  18. const obj = Object.assign({}, request, {
  19. path: filePath,
  20. relativePath:
  21. request.relativePath &&
  22. resolver.join(request.relativePath, this.filename)
  23. });
  24. resolver.doResolve(
  25. target,
  26. obj,
  27. "using path: " + filePath,
  28. resolveContext,
  29. callback
  30. );
  31. });
  32. }
  33. };