| [9af201e] | 1 | /*
|
|---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
|---|
| 3 | Author Tobias Koppers @sokra
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | "use strict";
|
|---|
| 7 |
|
|---|
| 8 | const EnableLibraryPlugin = require("./library/EnableLibraryPlugin");
|
|---|
| 9 |
|
|---|
| 10 | /** @typedef {import("../declarations/WebpackOptions").AuxiliaryComment} AuxiliaryComment */
|
|---|
| 11 | /** @typedef {import("../declarations/WebpackOptions").LibraryExport} LibraryExport */
|
|---|
| 12 | /** @typedef {import("../declarations/WebpackOptions").LibraryName} LibraryName */
|
|---|
| 13 | /** @typedef {import("../declarations/WebpackOptions").LibraryType} LibraryType */
|
|---|
| 14 | /** @typedef {import("../declarations/WebpackOptions").UmdNamedDefine} UmdNamedDefine */
|
|---|
| 15 | /** @typedef {import("./Compiler")} Compiler */
|
|---|
| 16 |
|
|---|
| 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 | /**
|
|---|
| 38 | * Applies the plugin by registering its hooks on the compiler.
|
|---|
| 39 | * @param {Compiler} compiler the compiler instance
|
|---|
| 40 | * @returns {void}
|
|---|
| 41 | */
|
|---|
| 42 | apply(compiler) {
|
|---|
| 43 | const { output } = compiler.options;
|
|---|
| 44 | output.library = this.library;
|
|---|
| 45 | new EnableLibraryPlugin(this.library.type).apply(compiler);
|
|---|
| 46 | }
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | module.exports = LibraryTemplatePlugin;
|
|---|