UseFilePlugin.js 798 B

1234567891011121314151617181920212223242526
  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.getHook(this.source).tapAsync("UseFilePlugin", (request, resolveContext, callback) => {
  15. const filePath = resolver.join(request.path, this.filename);
  16. const obj = Object.assign({}, request, {
  17. path: filePath,
  18. relativePath: request.relativePath && resolver.join(request.relativePath, this.filename)
  19. });
  20. resolver.doResolve(target, obj, "using path: " + filePath, resolveContext, callback);
  21. });
  22. }
  23. };