DelegatedPlugin.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const DelegatedModuleFactoryPlugin = require("./DelegatedModuleFactoryPlugin");
  7. const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
  8. const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency");
  9. const NullFactory = require("./NullFactory");
  10. class DelegatedPlugin {
  11. constructor(options) {
  12. this.options = options;
  13. }
  14. apply(compiler) {
  15. compiler.hooks.compilation.tap(
  16. "DelegatedPlugin",
  17. (compilation, { normalModuleFactory }) => {
  18. compilation.dependencyFactories.set(
  19. DelegatedSourceDependency,
  20. normalModuleFactory
  21. );
  22. compilation.dependencyFactories.set(
  23. DelegatedExportsDependency,
  24. new NullFactory()
  25. );
  26. }
  27. );
  28. compiler.hooks.compile.tap("DelegatedPlugin", ({ normalModuleFactory }) => {
  29. new DelegatedModuleFactoryPlugin(this.options).apply(normalModuleFactory);
  30. });
  31. }
  32. }
  33. module.exports = DelegatedPlugin;