ExternalsPlugin.js 933 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
  7. /** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
  8. /** @typedef {import("./Compiler")} Compiler */
  9. const PLUGIN_NAME = "ExternalsPlugin";
  10. class ExternalsPlugin {
  11. /**
  12. * @param {string | undefined} type default external type
  13. * @param {Externals} externals externals config
  14. */
  15. constructor(type, externals) {
  16. this.type = type;
  17. this.externals = externals;
  18. }
  19. /**
  20. * Apply the plugin
  21. * @param {Compiler} compiler the compiler instance
  22. * @returns {void}
  23. */
  24. apply(compiler) {
  25. compiler.hooks.compile.tap(PLUGIN_NAME, ({ normalModuleFactory }) => {
  26. new ExternalModuleFactoryPlugin(this.type, this.externals).apply(
  27. normalModuleFactory
  28. );
  29. });
  30. }
  31. }
  32. module.exports = ExternalsPlugin;