| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 12:44:33 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-16 23:19:39 +08:00
										 |  |  | const { ConcatSource, RawSource } = require("webpack-sources"); | 
					
						
							| 
									
										
										
										
											2021-01-04 22:30:11 +08:00
										 |  |  | const ExternalModule = require("./ExternalModule"); | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | const ModuleFilenameHelpers = require("./ModuleFilenameHelpers"); | 
					
						
							| 
									
										
										
										
											2021-09-07 18:40:07 +08:00
										 |  |  | const RuntimeGlobals = require("./RuntimeGlobals"); | 
					
						
							| 
									
										
										
										
											2021-09-08 19:09:01 +08:00
										 |  |  | const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin"); | 
					
						
							| 
									
										
										
										
											2017-01-19 12:44:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | /** @typedef {import("webpack-sources").Source} Source */ | 
					
						
							| 
									
										
										
										
											2025-08-20 18:50:12 +08:00
										 |  |  | /** @typedef {import("../declarations/WebpackOptions").DevtoolNamespace} DevtoolNamespace */ | 
					
						
							|  |  |  | /** @typedef {import("../declarations/WebpackOptions").DevtoolModuleFilenameTemplate} DevtoolModuleFilenameTemplate */ | 
					
						
							| 
									
										
										
										
											2018-11-09 05:59:19 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | /** @type {WeakMap<Source, Source>} */ | 
					
						
							|  |  |  | const cache = new WeakMap(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-18 21:47:24 +08:00
										 |  |  | const devtoolWarning = new RawSource(`/*
 | 
					
						
							|  |  |  |  * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development"). | 
					
						
							| 
									
										
										
										
											2021-01-01 14:07:17 +08:00
										 |  |  |  * This devtool is neither made for production nor for readable output files. | 
					
						
							| 
									
										
										
										
											2019-12-18 21:47:24 +08:00
										 |  |  |  * It uses "eval()" calls to create a separate source file in the browser devtools. | 
					
						
							|  |  |  |  * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
 | 
					
						
							|  |  |  |  * or disable the default devtool with "devtool: false". | 
					
						
							|  |  |  |  * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
 | 
					
						
							| 
									
										
										
										
											2019-12-16 23:19:39 +08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-12-18 21:47:24 +08:00
										 |  |  | `);
 | 
					
						
							| 
									
										
										
										
											2019-12-16 23:19:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2024-06-11 21:09:50 +08:00
										 |  |  |  * @typedef {object} EvalDevToolModulePluginOptions | 
					
						
							| 
									
										
										
										
											2025-08-20 18:50:12 +08:00
										 |  |  |  * @property {DevtoolNamespace=} namespace namespace | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  |  * @property {string=} sourceUrlComment source url comment | 
					
						
							| 
									
										
										
										
											2025-08-20 18:50:12 +08:00
										 |  |  |  * @property {DevtoolModuleFilenameTemplate=} moduleFilenameTemplate module filename template | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | const PLUGIN_NAME = "EvalDevToolModulePlugin"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 12:44:33 +08:00
										 |  |  | class EvalDevToolModulePlugin { | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {EvalDevToolModulePluginOptions=} options options | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2024-08-06 11:08:48 +08:00
										 |  |  | 	constructor(options = {}) { | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 		this.namespace = options.namespace || ""; | 
					
						
							|  |  |  | 		this.sourceUrlComment = options.sourceUrlComment || "\n//# sourceURL=[url]"; | 
					
						
							|  |  |  | 		this.moduleFilenameTemplate = | 
					
						
							|  |  |  | 			options.moduleFilenameTemplate || | 
					
						
							|  |  |  | 			"webpack://[namespace]/[resourcePath]?[loaders]"; | 
					
						
							| 
									
										
										
										
											2017-01-19 12:44:33 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-09 05:59:19 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-04-23 16:48:36 +08:00
										 |  |  | 	 * Apply the plugin | 
					
						
							| 
									
										
										
										
											2018-11-09 05:59:19 +08:00
										 |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-19 12:44:33 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => { | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 			const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation); | 
					
						
							|  |  |  | 			hooks.renderModuleContent.tap( | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 				PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2024-10-10 23:37:04 +08:00
										 |  |  | 				(source, module, { chunk, runtimeTemplate, chunkGraph }) => { | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 					const cacheEntry = cache.get(source); | 
					
						
							|  |  |  | 					if (cacheEntry !== undefined) return cacheEntry; | 
					
						
							| 
									
										
										
										
											2021-01-04 22:30:11 +08:00
										 |  |  | 					if (module instanceof ExternalModule) { | 
					
						
							|  |  |  | 						cache.set(source, source); | 
					
						
							|  |  |  | 						return source; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 					const content = source.source(); | 
					
						
							| 
									
										
										
										
											2024-06-09 09:31:31 +08:00
										 |  |  | 					const namespace = compilation.getPath(this.namespace, { | 
					
						
							| 
									
										
										
										
											2024-10-10 23:37:04 +08:00
										 |  |  | 						chunk | 
					
						
							| 
									
										
										
										
											2024-06-09 09:31:31 +08:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 					const str = ModuleFilenameHelpers.createFilename( | 
					
						
							|  |  |  | 						module, | 
					
						
							|  |  |  | 						{ | 
					
						
							|  |  |  | 							moduleFilenameTemplate: this.moduleFilenameTemplate, | 
					
						
							| 
									
										
										
										
											2024-06-09 09:31:31 +08:00
										 |  |  | 							namespace | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 						}, | 
					
						
							|  |  |  | 						{ | 
					
						
							|  |  |  | 							requestShortener: runtimeTemplate.requestShortener, | 
					
						
							| 
									
										
										
										
											2021-09-22 18:12:46 +08:00
										 |  |  | 							chunkGraph, | 
					
						
							|  |  |  | 							hashFunction: compilation.outputOptions.hashFunction | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 					const footer = `\n${this.sourceUrlComment.replace( | 
					
						
							|  |  |  | 						/\[url\]/g, | 
					
						
							|  |  |  | 						encodeURI(str) | 
					
						
							|  |  |  | 							.replace(/%2F/g, "/") | 
					
						
							|  |  |  | 							.replace(/%20/g, "_") | 
					
						
							|  |  |  | 							.replace(/%5E/g, "^") | 
					
						
							|  |  |  | 							.replace(/%5C/g, "\\") | 
					
						
							|  |  |  | 							.replace(/^\//, "") | 
					
						
							|  |  |  | 					)}`;
 | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 					const result = new RawSource( | 
					
						
							| 
									
										
										
										
											2021-09-07 18:40:07 +08:00
										 |  |  | 						`eval(${ | 
					
						
							|  |  |  | 							compilation.outputOptions.trustedTypes | 
					
						
							|  |  |  | 								? `${RuntimeGlobals.createScript}(${JSON.stringify( | 
					
						
							| 
									
										
										
										
											2025-06-27 01:10:49 +08:00
										 |  |  | 										`{${content + footer}\n}` | 
					
						
							| 
									
										
										
										
											2024-06-11 21:26:12 +08:00
										 |  |  | 									)})`
 | 
					
						
							| 
									
										
										
										
											2025-06-27 01:10:49 +08:00
										 |  |  | 								: JSON.stringify(`{${content + footer}\n}`) | 
					
						
							| 
									
										
										
										
											2021-09-07 18:40:07 +08:00
										 |  |  | 						});`
 | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 					); | 
					
						
							|  |  |  | 					cache.set(source, result); | 
					
						
							|  |  |  | 					return result; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2021-02-11 02:14:50 +08:00
										 |  |  | 			hooks.inlineInRuntimeBailout.tap( | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 				PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2021-02-11 02:14:50 +08:00
										 |  |  | 				() => "the eval devtool is used." | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2019-12-16 23:19:39 +08:00
										 |  |  | 			hooks.render.tap( | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 				PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 				(source) => new ConcatSource(devtoolWarning, source) | 
					
						
							| 
									
										
										
										
											2019-12-16 23:19:39 +08:00
										 |  |  | 			); | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 			hooks.chunkHash.tap(PLUGIN_NAME, (chunk, hash) => { | 
					
						
							|  |  |  | 				hash.update(PLUGIN_NAME); | 
					
						
							| 
									
										
										
										
											2019-12-18 21:47:24 +08:00
										 |  |  | 				hash.update("2"); | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2021-09-07 18:40:07 +08:00
										 |  |  | 			if (compilation.outputOptions.trustedTypes) { | 
					
						
							|  |  |  | 				compilation.hooks.additionalModuleRuntimeRequirements.tap( | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 					PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 					(module, set, _context) => { | 
					
						
							| 
									
										
										
										
											2021-09-07 18:40:07 +08:00
										 |  |  | 						set.add(RuntimeGlobals.createScript); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-19 12:44:33 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-01-19 12:44:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | module.exports = EvalDevToolModulePlugin; |