您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ModuleKindPlugin.js 816B

12345678910111213141516171819202122232425262728
  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 ModuleKindPlugin {
  7. constructor(source, target) {
  8. this.source = source;
  9. this.target = target;
  10. }
  11. apply(resolver) {
  12. const target = resolver.ensureHook(this.target);
  13. resolver.getHook(this.source).tapAsync("ModuleKindPlugin", (request, resolveContext, callback) => {
  14. if(!request.module) return callback();
  15. const obj = Object.assign({}, request);
  16. delete obj.module;
  17. resolver.doResolve(target, obj, "resolve as module", resolveContext, (err, result) => {
  18. if(err) return callback(err);
  19. // Don't allow other alternatives
  20. if(result === undefined) return callback(null, null);
  21. callback(null, result);
  22. });
  23. });
  24. }
  25. };