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

Method apply

lib/EvalDevToolModulePlugin.js:63–134  ·  lib/EvalDevToolModulePlugin.js::EvalDevToolModulePlugin.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

61 * @returns {void}
62 */
63 apply(compiler) {
64 compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
65 const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
66 hooks.renderModuleContent.tap(
67 PLUGIN_NAME,
68 (source, module, { chunk, runtimeTemplate, chunkGraph }) => {
69 const cacheEntry = cache.get(source);
70 if (cacheEntry !== undefined) return cacheEntry;
71 if (module instanceof ExternalModule) {
72 cache.set(source, source);
73 return source;
74 }
75 const content = source.source();
76 const namespace = compilation.getPath(this.namespace, {
77 chunk
78 });
79 const str = ModuleFilenameHelpers.createFilename(
80 module,
81 {
82 moduleFilenameTemplate: this.moduleFilenameTemplate,
83 namespace
84 },
85 {
86 requestShortener: runtimeTemplate.requestShortener,
87 chunkGraph,
88 hashFunction: compilation.outputOptions.hashFunction
89 }
90 );
91 const footer = `\n${this.sourceUrlComment.replace(
92 /\[url\]/g,
93 encodeURI(str)
94 .replace(/%2F/g, class="st">"/")
95 .replace(/%20/g, class="st">"_")
96 .replace(/%5E/g, class="st">"^")
97 .replace(/%5C/g, class="st">"\\")
98 .replace(/^\class="cm">//, class="st">"")
99 )}`;
100 const result = new RawSource(
101 `eval(${
102 compilation.outputOptions.trustedTypes
103 ? `${RuntimeGlobals.createScript}(${JSON.stringify(
104 `{${content + footer}\n}`
105 )})`
106 : JSON.stringify(`{${content + footer}\n}`)
107 });`
108 );
109 cache.set(source, result);
110 return result;
111 }
112 );
113 hooks.inlineInRuntimeBailout.tap(
114 PLUGIN_NAME,
115 () => class="st">"the eval devtool is used."
116 );
117 hooks.render.tap(
118 PLUGIN_NAME,
119 (source) => new ConcatSource(devtoolWarning, source)
120 );

Callers

nothing calls this directly

Calls 9

tapMethod · 0.80
sourceMethod · 0.80
getPathMethod · 0.80
getCompilationHooksMethod · 0.45
getMethod · 0.45
setMethod · 0.45
replaceMethod · 0.45
updateMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected