AppendPlugin.js 758 B

123456789101112131415161718192021222324252627282930313233
  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 AppendPlugin {
  7. constructor(source, appending, target) {
  8. this.source = source;
  9. this.appending = appending;
  10. this.target = target;
  11. }
  12. apply(resolver) {
  13. const target = resolver.ensureHook(this.target);
  14. resolver
  15. .getHook(this.source)
  16. .tapAsync("AppendPlugin", (request, resolveContext, callback) => {
  17. const obj = Object.assign({}, request, {
  18. path: request.path + this.appending,
  19. relativePath:
  20. request.relativePath && request.relativePath + this.appending
  21. });
  22. resolver.doResolve(
  23. target,
  24. obj,
  25. this.appending,
  26. resolveContext,
  27. callback
  28. );
  29. });
  30. }
  31. };