ExternalsPlugin.js 899 B

12345678910111213141516171819202122232425262728293031323334353637
  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. class ExternalsPlugin {
  10. /**
  11. * @param {string | undefined} type default external type
  12. * @param {Externals} externals externals config
  13. */
  14. constructor(type, externals) {
  15. this.type = type;
  16. this.externals = externals;
  17. }
  18. /**
  19. * Apply the plugin
  20. * @param {Compiler} compiler the compiler instance
  21. * @returns {void}
  22. */
  23. apply(compiler) {
  24. compiler.hooks.compile.tap("ExternalsPlugin", ({ normalModuleFactory }) => {
  25. new ExternalModuleFactoryPlugin(this.type, this.externals).apply(
  26. normalModuleFactory
  27. );
  28. });
  29. }
  30. }
  31. module.exports = ExternalsPlugin;