CloneBasenamePlugin.js 858 B

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