| 
									
										
										
										
											2020-02-28 00:49:47 +08:00
										 |  |  | const svgToMiniDataURI = require("mini-svg-data-uri"); | 
					
						
							|  |  |  | const mimeTypes = require("mime-types"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-01 22:36:51 +08:00
										 |  |  | /** @typedef {import("../../../../").GeneratorOptionsByModuleTypeKnown} GeneratorOptionsByModuleTypeKnown */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-05 18:11:02 +08:00
										 |  |  | /** @type {import("../../../../").Configuration} */ | 
					
						
							| 
									
										
										
										
											2020-02-28 00:49:47 +08:00
										 |  |  | module.exports = { | 
					
						
							|  |  |  | 	mode: "development", | 
					
						
							|  |  |  | 	module: { | 
					
						
							|  |  |  | 		rules: [ | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				test: /\.(png|svg|jpg)$/, | 
					
						
							|  |  |  | 				type: "asset/inline", | 
					
						
							| 
									
										
										
										
											2025-05-01 22:36:51 +08:00
										 |  |  | 				/** @type {GeneratorOptionsByModuleTypeKnown["asset/inline"]} */ | 
					
						
							| 
									
										
										
										
											2020-02-28 00:49:47 +08:00
										 |  |  | 				generator: { | 
					
						
							|  |  |  | 					dataUrl: (source, { filename, module }) => { | 
					
						
							|  |  |  | 						if (filename.endsWith("?foo=bar")) { | 
					
						
							|  |  |  | 							if (typeof source !== "string") { | 
					
						
							|  |  |  | 								source = source.toString(); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							return svgToMiniDataURI(source); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-01 22:36:51 +08:00
										 |  |  | 						const mimeType = mimeTypes.lookup( | 
					
						
							|  |  |  | 							/** @type {string} */ | 
					
						
							|  |  |  | 							(module.nameForCondition()) | 
					
						
							|  |  |  | 						); | 
					
						
							| 
									
										
										
										
											2020-02-28 00:49:47 +08:00
										 |  |  | 						const encodedContent = source.toString("base64"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						return `data:${mimeType};base64,${encodedContent}`; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		] | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; |