| 
									
										
										
										
											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"); | 
					
						
							| 
									
										
										
										
											2019-10-11 21:46:57 +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 */ | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 12:44:33 +08:00
										 |  |  | class EvalDevToolModulePlugin { | 
					
						
							| 
									
										
										
										
											2017-10-20 04:23:28 +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) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		compiler.hooks.compilation.tap("EvalDevToolModulePlugin", compilation => { | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 			const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation); | 
					
						
							|  |  |  | 			hooks.renderModuleContent.tap( | 
					
						
							|  |  |  | 				"EvalDevToolModulePlugin", | 
					
						
							|  |  |  | 				(source, module, { runtimeTemplate, chunkGraph }) => { | 
					
						
							|  |  |  | 					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(); | 
					
						
							|  |  |  | 					const str = ModuleFilenameHelpers.createFilename( | 
					
						
							|  |  |  | 						module, | 
					
						
							|  |  |  | 						{ | 
					
						
							|  |  |  | 							moduleFilenameTemplate: this.moduleFilenameTemplate, | 
					
						
							|  |  |  | 							namespace: this.namespace | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 						{ | 
					
						
							|  |  |  | 							requestShortener: runtimeTemplate.requestShortener, | 
					
						
							| 
									
										
										
										
											2021-09-22 18:12:46 +08:00
										 |  |  | 							chunkGraph, | 
					
						
							|  |  |  | 							hashFunction: compilation.outputOptions.hashFunction | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +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(/^\//, "") | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 					const result = new RawSource( | 
					
						
							|  |  |  | 						`eval(${JSON.stringify(content + footer)});` | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					cache.set(source, result); | 
					
						
							|  |  |  | 					return result; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2021-02-11 02:14:50 +08:00
										 |  |  | 			hooks.inlineInRuntimeBailout.tap( | 
					
						
							|  |  |  | 				"EvalDevToolModulePlugin", | 
					
						
							|  |  |  | 				() => "the eval devtool is used." | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2019-12-16 23:19:39 +08:00
										 |  |  | 			hooks.render.tap( | 
					
						
							|  |  |  | 				"EvalDevToolModulePlugin", | 
					
						
							|  |  |  | 				source => new ConcatSource(devtoolWarning, source) | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 			hooks.chunkHash.tap("EvalDevToolModulePlugin", (chunk, hash) => { | 
					
						
							|  |  |  | 				hash.update("EvalDevToolModulePlugin"); | 
					
						
							| 
									
										
										
										
											2019-12-18 21:47:24 +08:00
										 |  |  | 				hash.update("2"); | 
					
						
							| 
									
										
										
										
											2019-10-02 17:19:44 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											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; |