DelegatedPlugin.js 939B

12345678910111213141516171819202122232425262728293031
  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.plugin("compilation", (compilation, params) => {
  16. compilation.dependencyFactories.set(DelegatedSourceDependency, params.normalModuleFactory);
  17. compilation.dependencyFactories.set(DelegatedExportsDependency, new NullFactory());
  18. });
  19. compiler.plugin("compile", (params) => {
  20. params.normalModuleFactory.apply(new DelegatedModuleFactoryPlugin(this.options));
  21. });
  22. }
  23. }
  24. module.exports = DelegatedPlugin;