DelegatedPlugin.js 1015 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. /** @typedef {import("./Compiler")} Compiler */
  9. class DelegatedPlugin {
  10. constructor(options) {
  11. this.options = options;
  12. }
  13. /**
  14. * Apply the plugin
  15. * @param {Compiler} compiler the compiler instance
  16. * @returns {void}
  17. */
  18. apply(compiler) {
  19. compiler.hooks.compilation.tap(
  20. "DelegatedPlugin",
  21. (compilation, { normalModuleFactory }) => {
  22. compilation.dependencyFactories.set(
  23. DelegatedSourceDependency,
  24. normalModuleFactory
  25. );
  26. }
  27. );
  28. compiler.hooks.compile.tap("DelegatedPlugin", ({ normalModuleFactory }) => {
  29. new DelegatedModuleFactoryPlugin({
  30. associatedObjectForCache: compiler.root,
  31. ...this.options
  32. }).apply(normalModuleFactory);
  33. });
  34. }
  35. }
  36. module.exports = DelegatedPlugin;