AppendPlugin.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. /** @typedef {import("./Resolver")} Resolver */
  7. /** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */
  8. module.exports = class AppendPlugin {
  9. /**
  10. * @param {string | ResolveStepHook} source source
  11. * @param {string} appending appending
  12. * @param {string | ResolveStepHook} target target
  13. */
  14. constructor(source, appending, target) {
  15. this.source = source;
  16. this.appending = appending;
  17. this.target = target;
  18. }
  19. /**
  20. * @param {Resolver} resolver the resolver
  21. * @returns {void}
  22. */
  23. apply(resolver) {
  24. const target = resolver.ensureHook(this.target);
  25. resolver
  26. .getHook(this.source)
  27. .tapAsync("AppendPlugin", (request, resolveContext, callback) => {
  28. const obj = {
  29. ...request,
  30. path: request.path + this.appending,
  31. relativePath:
  32. request.relativePath && request.relativePath + this.appending
  33. };
  34. resolver.doResolve(
  35. target,
  36. obj,
  37. this.appending,
  38. resolveContext,
  39. callback
  40. );
  41. });
  42. }
  43. };