MCPcopy
hub / github.com/webpack/webpack / apply

Method apply

lib/library/EnableLibraryPlugin.js:83–309  ·  view source on GitHub ↗

* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}

(compiler)

Source from the content-addressed store, hash-verified

81 * @returns {void}
82 */
83 apply(compiler) {
84 const { type, options } = this;
85
86 // Only enable once
87 const enabled = getEnabledTypes(compiler);
88 if (enabled.has(type)) return;
89 enabled.add(type);
90
91 if (typeof options.additionalApply === "function") {
92 options.additionalApply();
93 }
94
95 if (typeof type === "string") {
96 const enableExportProperty = () => {
97 const ExportPropertyLibraryPlugin = require("./ExportPropertyLibraryPlugin");
98
99 new ExportPropertyLibraryPlugin({
100 type
101 }).apply(compiler);
102 };
103 switch (type) {
104 case "var": {
105 // @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
106 const AssignLibraryPlugin = require("./AssignLibraryPlugin");
107
108 new AssignLibraryPlugin({
109 type,
110 prefix: [],
111 declare: "var",
112 unnamed: "error"
113 }).apply(compiler);
114 break;
115 }
116 case "assign-properties": {
117 // @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
118 const AssignLibraryPlugin = require("./AssignLibraryPlugin");
119
120 new AssignLibraryPlugin({
121 type,
122 prefix: [],
123 declare: false,
124 unnamed: "error",
125 named: "copy"
126 }).apply(compiler);
127 break;
128 }
129 case "assign": {
130 // @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
131 const AssignLibraryPlugin = require("./AssignLibraryPlugin");
132
133 new AssignLibraryPlugin({
134 type,
135 prefix: [],
136 declare: false,
137 unnamed: "error"
138 }).apply(compiler);
139 break;
140 }

Callers

nothing calls this directly

Calls 5

getEnabledTypesFunction · 0.70
applyMethod · 0.65
requireFunction · 0.50
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected