| 
									
										
										
										
											2018-11-20 19:05:12 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const RuntimeGlobals = require("../RuntimeGlobals"); | 
					
						
							|  |  |  | const RuntimeModule = require("../RuntimeModule"); | 
					
						
							| 
									
										
										
										
											2018-12-18 05:05:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-25 03:37:58 +08:00
										 |  |  | /** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} OutputOptions */ | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | /** @typedef {import("../Compilation")} Compilation */ | 
					
						
							| 
									
										
										
										
											2023-05-25 03:37:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 19:05:12 +08:00
										 |  |  | class PublicPathRuntimeModule extends RuntimeModule { | 
					
						
							| 
									
										
										
										
											2023-05-25 03:37:58 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {OutputOptions["publicPath"]} publicPath public path | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-04-14 22:38:01 +08:00
										 |  |  | 	constructor(publicPath) { | 
					
						
							| 
									
										
										
										
											2020-12-11 21:32:42 +08:00
										 |  |  | 		super("publicPath", RuntimeModule.STAGE_BASIC); | 
					
						
							| 
									
										
										
										
											2021-04-14 22:38:01 +08:00
										 |  |  | 		this.publicPath = publicPath; | 
					
						
							| 
									
										
										
										
											2018-11-20 19:05:12 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2023-06-17 01:13:03 +08:00
										 |  |  | 	 * @returns {string | null} runtime code | 
					
						
							| 
									
										
										
										
											2018-11-20 19:05:12 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	generate() { | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 		const { publicPath } = this; | 
					
						
							|  |  |  | 		const compilation = /** @type {Compilation} */ (this.compilation); | 
					
						
							| 
									
										
										
										
											2020-09-15 05:27:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-18 16:12:13 +08:00
										 |  |  | 		return `${RuntimeGlobals.publicPath} = ${JSON.stringify( | 
					
						
							| 
									
										
										
										
											2021-04-14 22:38:01 +08:00
										 |  |  | 			compilation.getPath(publicPath || "", { | 
					
						
							|  |  |  | 				hash: compilation.hash || "XXXX" | 
					
						
							| 
									
										
										
										
											2020-09-15 05:27:38 +08:00
										 |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2020-09-18 16:12:13 +08:00
										 |  |  | 		)};`;
 | 
					
						
							| 
									
										
										
										
											2020-09-15 05:27:38 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-20 19:05:12 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = PublicPathRuntimeModule; |