| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2017-01-06 23:17:22 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 23:17:22 +08:00
										 |  |  | const ConcatSource = require("webpack-sources").ConcatSource; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class JsonpExportMainTemplatePlugin { | 
					
						
							|  |  |  | 	constructor(name) { | 
					
						
							|  |  |  | 		this.name = name; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	apply(compilation) { | 
					
						
							| 
									
										
										
										
											2017-12-16 08:23:46 +08:00
										 |  |  | 		const { | 
					
						
							|  |  |  | 			mainTemplate, | 
					
						
							|  |  |  | 			chunkTemplate | 
					
						
							|  |  |  | 		} = compilation; | 
					
						
							| 
									
										
										
										
											2017-01-06 23:17:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-16 08:14:19 +08:00
										 |  |  | 		const onRenderWithEntry = (source, chunk, hash) => { | 
					
						
							| 
									
										
										
										
											2017-11-29 01:43:01 +08:00
										 |  |  | 			const name = mainTemplate.getAssetPath(this.name || "", { | 
					
						
							| 
									
										
										
										
											2017-12-08 18:05:45 +08:00
										 |  |  | 				hash, | 
					
						
							|  |  |  | 				chunk | 
					
						
							| 
									
										
										
										
											2017-01-06 23:17:22 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 			return new ConcatSource(`${name}(`, source, ");"); | 
					
						
							| 
									
										
										
										
											2017-12-16 08:14:19 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-01-06 23:17:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-16 09:07:32 +08:00
										 |  |  | 		for(const template of [mainTemplate, chunkTemplate]) { | 
					
						
							| 
									
										
										
										
											2017-12-16 15:46:41 +08:00
										 |  |  | 			template.hooks.renderWithEntry.tap("JsonpExportMainTemplatePlugin", onRenderWithEntry); | 
					
						
							| 
									
										
										
										
											2017-12-16 09:07:32 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 18:05:45 +08:00
										 |  |  | 		mainTemplate.hooks.globalHashPaths.tap("JsonpExportMainTemplatePlugin", paths => { | 
					
						
							| 
									
										
										
										
											2017-01-06 23:17:22 +08:00
										 |  |  | 			if(this.name) paths.push(this.name); | 
					
						
							|  |  |  | 			return paths; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 18:05:45 +08:00
										 |  |  | 		mainTemplate.hooks.hash.tap("JsonpExportMainTemplatePlugin", hash => { | 
					
						
							| 
									
										
										
										
											2017-01-06 23:17:22 +08:00
										 |  |  | 			hash.update("jsonp export"); | 
					
						
							|  |  |  | 			hash.update(`${this.name}`); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-01-06 23:17:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | module.exports = JsonpExportMainTemplatePlugin; |