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

Method apply

lib/optimize/ModuleConcatenationPlugin.js:84–562  ·  lib/optimize/ModuleConcatenationPlugin.js::ModuleConcatenationPlugin.apply

* 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

82 * @returns {void}
83 */
84 apply(compiler) {
85 const { _backCompat: backCompat } = compiler;
86 compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
87 if (compilation.moduleMemCaches) {
88 throw new Error(
89 class="st">"optimization.concatenateModules can't be used with cacheUnaffected as module concatenation is a global effect"
90 );
91 }
92 const moduleGraph = compilation.moduleGraph;
93 /** @type {Map<Module, string | ((requestShortener: RequestShortener) => string)>} */
94 const bailoutReasonMap = new Map();
95
96 /**
97 * Sets bailout reason.
98 * @param {Module} module the module
99 * @param {string | ((requestShortener: RequestShortener) => string)} reason the reason
100 */
101 const setBailoutReason = (module, reason) => {
102 setInnerBailoutReason(module, reason);
103 moduleGraph
104 .getOptimizationBailout(module)
105 .push(
106 typeof reason === class="st">"function"
107 ? (rs) => formatBailoutReason(reason(rs))
108 : formatBailoutReason(reason)
109 );
110 };
111
112 /**
113 * Sets inner bailout reason.
114 * @param {Module} module the module
115 * @param {string | ((requestShortener: RequestShortener) => string)} reason the reason
116 */
117 const setInnerBailoutReason = (module, reason) => {
118 bailoutReasonMap.set(module, reason);
119 };
120
121 /**
122 * Gets inner bailout reason.
123 * @param {Module} module the module
124 * @param {RequestShortener} requestShortener the request shortener
125 * @returns {string | ((requestShortener: RequestShortener) => string) | undefined} the reason
126 */
127 const getInnerBailoutReason = (module, requestShortener) => {
128 const reason = bailoutReasonMap.get(module);
129 if (typeof reason === class="st">"function") return reason(requestShortener);
130 return reason;
131 };
132
133 /**
134 * Format bailout warning.
135 * @param {Module} module the module
136 * @param {Problem} problem the problem
137 * @returns {(requestShortener: RequestShortener) => string} the reason
138 */
139 const formatBailoutWarning = (module, problem) => (requestShortener) => {
140 if (typeof problem === class="st">"function") {
141 return formatBailoutReason(

Callers

nothing calls this directly

Calls 15

_getImportsMethod · 0.95
_tryToAddMethod · 0.95
addWarningMethod · 0.95
isEmptyMethod · 0.95
getModulesMethod · 0.95
getWarningsSortedMethod · 0.95
getMergedModuleRuntimeFunction · 0.85
filterRuntimeFunction · 0.85
buildFunction · 0.85
tapMethod · 0.80
timeMethod · 0.80
isAsyncMethod · 0.80

Tested by

no test coverage detected