LibraryTemplatePlugin.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const EnableLibraryPlugin = require("./library/EnableLibraryPlugin");
  7. /** @typedef {import("../declarations/WebpackOptions").AuxiliaryComment} AuxiliaryComment */
  8. /** @typedef {import("../declarations/WebpackOptions").LibraryExport} LibraryExport */
  9. /** @typedef {import("../declarations/WebpackOptions").LibraryName} LibraryName */
  10. /** @typedef {import("../declarations/WebpackOptions").LibraryType} LibraryType */
  11. /** @typedef {import("../declarations/WebpackOptions").UmdNamedDefine} UmdNamedDefine */
  12. /** @typedef {import("./Compiler")} Compiler */
  13. // TODO webpack 6 remove
  14. class LibraryTemplatePlugin {
  15. /**
  16. * @param {LibraryName} name name of library
  17. * @param {LibraryType} target type of library
  18. * @param {UmdNamedDefine} umdNamedDefine setting this to true will name the UMD module
  19. * @param {AuxiliaryComment} auxiliaryComment comment in the UMD wrapper
  20. * @param {LibraryExport} exportProperty which export should be exposed as library
  21. */
  22. constructor(name, target, umdNamedDefine, auxiliaryComment, exportProperty) {
  23. this.library = {
  24. type: target || "var",
  25. name,
  26. umdNamedDefine,
  27. auxiliaryComment,
  28. export: exportProperty
  29. };
  30. }
  31. /**
  32. * Apply the plugin
  33. * @param {Compiler} compiler the compiler instance
  34. * @returns {void}
  35. */
  36. apply(compiler) {
  37. const { output } = compiler.options;
  38. output.library = this.library;
  39. new EnableLibraryPlugin(this.library.type).apply(compiler);
  40. }
  41. }
  42. module.exports = LibraryTemplatePlugin;