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

Method apply

lib/HotModuleReplacementPlugin.js:120–990  ·  lib/HotModuleReplacementPlugin.js::HotModuleReplacementPlugin.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

118 * @returns {void}
119 */
120 apply(compiler) {
121 const { _backCompat: backCompat } = compiler;
122 if (compiler.options.output.strictModuleErrorHandling === undefined) {
123 compiler.options.output.strictModuleErrorHandling = true;
124 }
125 const runtimeRequirements = [RuntimeGlobals.module];
126
127 /**
128 * Creates an accept handler.
129 * @param {JavascriptParser} parser the parser
130 * @param {typeof ModuleHotAcceptDependency} ParamDependency dependency
131 * @returns {(expr: CallExpression) => boolean | undefined} callback
132 */
133 const createAcceptHandler = (parser, ParamDependency) => {
134 const { hotAcceptCallback, hotAcceptWithoutCallback } =
135 HotModuleReplacementPlugin.getParserHooks(parser);
136
137 return (expr) => {
138 const module = parser.state.module;
139 const dep = new ConstDependency(
140 `${module.moduleArgument}.hot.accept`,
141 /** @type {Range} */ (expr.callee.range),
142 runtimeRequirements
143 );
144 dep.loc = /** @type {DependencyLocation} */ (expr.loc);
145 module.addPresentationalDependency(dep);
146 /** @type {BuildInfo} */
147 (module.buildInfo).moduleConcatenationBailout =
148 class="st">"Hot Module Replacement";
149
150 if (expr.arguments.length >= 1) {
151 const arg = parser.evaluateExpression(expr.arguments[0]);
152 /** @type {BasicEvaluatedExpression[]} */
153 let params = [];
154 if (arg.isString()) {
155 params = [arg];
156 } else if (arg.isArray()) {
157 params =
158 /** @type {BasicEvaluatedExpression[]} */
159 (arg.items).filter((param) => param.isString());
160 }
161 /** @type {Requests} */
162 const requests = [];
163 if (params.length > 0) {
164 for (const [idx, param] of params.entries()) {
165 const request = /** @type {string} */ (param.string);
166 const dep = new ParamDependency(
167 request,
168 /** @type {Range} */ (param.range)
169 );
170 dep.optional = true;
171 dep.setLocWithIndex(
172 /** @type {DependencyLocation} */ (expr.loc),
173 idx
174 );
175 module.addDependency(dep);
176 requests.push(request);
177 }

Callers

nothing calls this directly

Calls 15

addMethod · 0.95
hasMethod · 0.95
getRuntimeKeyFunction · 0.85
compareModulesByIdFunction · 0.85
keyToRuntimeFunction · 0.85
mergeRuntimeOwnedFunction · 0.85
forEachRuntimeFunction · 0.85
intersectRuntimeFunction · 0.85
subtractRuntimeFunction · 0.85
isSubsetFunction · 0.85
chunkHasCssFunction · 0.85
tapMethod · 0.80

Tested by

no test coverage detected