CloneBasenamePlugin.js 782 B

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