LibraryTemplatePlugin.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. /**
  8. * @import {
  9. * AuxiliaryComment,
  10. * LibraryExport,
  11. * LibraryName,
  12. * LibraryType,
  13. * UmdNamedDefine
  14. * } from "../declarations/WebpackOptions"
  15. */
  16. /** @import Compiler from "./Compiler" */
  17. // TODO webpack 6 remove
  18. class LibraryTemplatePlugin {
  19. /**
  20. * Creates an instance of LibraryTemplatePlugin.
  21. * @param {LibraryName} name name of library
  22. * @param {LibraryType} target type of library
  23. * @param {UmdNamedDefine} umdNamedDefine setting this to true will name the UMD module
  24. * @param {AuxiliaryComment} auxiliaryComment comment in the UMD wrapper
  25. * @param {LibraryExport} exportProperty which export should be exposed as library
  26. */
  27. constructor(name, target, umdNamedDefine, auxiliaryComment, exportProperty) {
  28. this.library = {
  29. type: target || "var",
  30. name,
  31. umdNamedDefine,
  32. auxiliaryComment,
  33. export: exportProperty
  34. };
  35. }
  36. /**
  37. * Applies the plugin by registering its hooks on the compiler.
  38. * @param {Compiler} compiler the compiler instance
  39. * @returns {void}
  40. */
  41. apply(compiler) {
  42. const { output } = compiler.options;
  43. output.library = this.library;
  44. new EnableLibraryPlugin(this.library.type).apply(compiler);
  45. }
  46. }
  47. module.exports = LibraryTemplatePlugin;