| 
									
										
										
										
											2014-03-05 16:58:51 +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-02-18 20:17:16 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const { OriginalSource, RawSource } = require("webpack-sources"); | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | const Module = require("./Module"); | 
					
						
							| 
									
										
										
										
											2018-11-17 01:18:44 +08:00
										 |  |  | const RuntimeGlobals = require("./RuntimeGlobals"); | 
					
						
							| 
									
										
										
										
											2017-02-20 16:17:51 +08:00
										 |  |  | const Template = require("./Template"); | 
					
						
							| 
									
										
										
										
											2018-10-18 22:02:45 +08:00
										 |  |  | const makeSerializable = require("./util/makeSerializable"); | 
					
						
							| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | /** @typedef {import("webpack-sources").Source} Source */ | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */ | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | /** @typedef {import("./Chunk")} Chunk */ | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | /** @typedef {import("./ChunkGraph")} ChunkGraph */ | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | /** @typedef {import("./Compilation")} Compilation */ | 
					
						
							|  |  |  | /** @typedef {import("./DependencyTemplates")} DependencyTemplates */ | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */ | 
					
						
							|  |  |  | /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */ | 
					
						
							| 
									
										
										
										
											2018-07-20 22:24:35 +08:00
										 |  |  | /** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */ | 
					
						
							| 
									
										
										
										
											2018-09-26 15:14:44 +08:00
										 |  |  | /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | /** @typedef {import("./RequestShortener")} RequestShortener */ | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */ | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */ | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | /** @typedef {import("./WebpackError")} WebpackError */ | 
					
						
							| 
									
										
										
										
											2019-07-17 22:02:33 +08:00
										 |  |  | /** @typedef {import("./util/Hash")} Hash */ | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */ | 
					
						
							| 
									
										
										
										
											2018-07-21 00:17:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {string|string[]} variableName the variable name or path | 
					
						
							|  |  |  |  * @param {string} type the module system | 
					
						
							|  |  |  |  * @returns {string} the generated source | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const getSourceForGlobalVariableExternal = (variableName, type) => { | 
					
						
							|  |  |  | 	if (!Array.isArray(variableName)) { | 
					
						
							|  |  |  | 		// make it an array as the look up works the same basically
 | 
					
						
							|  |  |  | 		variableName = [variableName]; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// needed for e.g. window["some"]["thing"]
 | 
					
						
							|  |  |  | 	const objectLookup = variableName.map(r => `[${JSON.stringify(r)}]`).join(""); | 
					
						
							|  |  |  | 	return `(function() { module.exports = ${type}${objectLookup}; }());`; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {string|string[]} moduleAndSpecifiers the module request | 
					
						
							|  |  |  |  * @returns {string} the generated source | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const getSourceForCommonJsExternal = moduleAndSpecifiers => { | 
					
						
							|  |  |  | 	if (!Array.isArray(moduleAndSpecifiers)) { | 
					
						
							|  |  |  | 		return `module.exports = require(${JSON.stringify(moduleAndSpecifiers)});`; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	const moduleName = moduleAndSpecifiers[0]; | 
					
						
							|  |  |  | 	const objectLookup = moduleAndSpecifiers | 
					
						
							|  |  |  | 		.slice(1) | 
					
						
							|  |  |  | 		.map(r => `[${JSON.stringify(r)}]`) | 
					
						
							|  |  |  | 		.join(""); | 
					
						
							| 
									
										
										
										
											2018-09-18 16:13:54 +08:00
										 |  |  | 	return `module.exports = require(${JSON.stringify( | 
					
						
							|  |  |  | 		moduleName | 
					
						
							|  |  |  | 	)})${objectLookup};`;
 | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {string} variableName the variable name to check | 
					
						
							|  |  |  |  * @param {string} request the request path | 
					
						
							|  |  |  |  * @param {RuntimeTemplate} runtimeTemplate the runtime template | 
					
						
							|  |  |  |  * @returns {string} the generated source | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const checkExternalVariable = (variableName, request, runtimeTemplate) => { | 
					
						
							|  |  |  | 	return `if(typeof ${variableName} === 'undefined') { ${runtimeTemplate.throwMissingModuleErrorBlock( | 
					
						
							|  |  |  | 		{ request } | 
					
						
							|  |  |  | 	)} }\n`;
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {string|number} id the module id | 
					
						
							|  |  |  |  * @param {boolean} optional true, if the module is optional | 
					
						
							| 
									
										
										
										
											2018-09-18 16:13:54 +08:00
										 |  |  |  * @param {string|string[]} request the request path | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  |  * @param {RuntimeTemplate} runtimeTemplate the runtime template | 
					
						
							|  |  |  |  * @returns {string} the generated source | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const getSourceForAmdOrUmdExternal = ( | 
					
						
							|  |  |  | 	id, | 
					
						
							|  |  |  | 	optional, | 
					
						
							|  |  |  | 	request, | 
					
						
							|  |  |  | 	runtimeTemplate | 
					
						
							|  |  |  | ) => { | 
					
						
							|  |  |  | 	const externalVariable = `__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier( | 
					
						
							|  |  |  | 		`${id}` | 
					
						
							|  |  |  | 	)}__`;
 | 
					
						
							|  |  |  | 	const missingModuleError = optional | 
					
						
							| 
									
										
										
										
											2018-09-18 16:13:54 +08:00
										 |  |  | 		? checkExternalVariable( | 
					
						
							|  |  |  | 				externalVariable, | 
					
						
							|  |  |  | 				Array.isArray(request) ? request.join(".") : request, | 
					
						
							|  |  |  | 				runtimeTemplate | 
					
						
							|  |  |  | 		  ) | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | 		: ""; | 
					
						
							|  |  |  | 	return `${missingModuleError}module.exports = ${externalVariable};`; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {boolean} optional true, if the module is optional | 
					
						
							| 
									
										
										
										
											2018-09-18 16:13:54 +08:00
										 |  |  |  * @param {string|string[]} request the request path | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  |  * @param {RuntimeTemplate} runtimeTemplate the runtime template | 
					
						
							|  |  |  |  * @returns {string} the generated source | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const getSourceForDefaultCase = (optional, request, runtimeTemplate) => { | 
					
						
							| 
									
										
										
										
											2018-09-18 16:13:54 +08:00
										 |  |  | 	if (!Array.isArray(request)) { | 
					
						
							|  |  |  | 		// make it an array as the look up works the same basically
 | 
					
						
							|  |  |  | 		request = [request]; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const variableName = request[0]; | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | 	const missingModuleError = optional | 
					
						
							| 
									
										
										
										
											2018-09-18 16:13:54 +08:00
										 |  |  | 		? checkExternalVariable(variableName, request.join("."), runtimeTemplate) | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | 		: ""; | 
					
						
							| 
									
										
										
										
											2018-09-18 16:13:54 +08:00
										 |  |  | 	const objectLookup = request | 
					
						
							|  |  |  | 		.slice(1) | 
					
						
							|  |  |  | 		.map(r => `[${JSON.stringify(r)}]`) | 
					
						
							|  |  |  | 		.join(""); | 
					
						
							|  |  |  | 	return `${missingModuleError}module.exports = ${variableName}${objectLookup};`; | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | const TYPES = new Set(["javascript"]); | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | const RUNTIME_REQUIREMENTS = new Set([RuntimeGlobals.module]); | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | class ExternalModule extends Module { | 
					
						
							| 
									
										
										
										
											2017-06-09 04:22:58 +08:00
										 |  |  | 	constructor(request, type, userRequest) { | 
					
						
							| 
									
										
										
										
											2018-01-31 04:40:44 +08:00
										 |  |  | 		super("javascript/dynamic", null); | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Info from Factory
 | 
					
						
							| 
									
										
										
										
											2018-07-20 22:24:35 +08:00
										 |  |  | 		/** @type {string | string[] | Record<string, string | string[]>} */ | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | 		this.request = request; | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | 		/** @type {string} */ | 
					
						
							| 
									
										
										
										
											2017-11-10 18:51:29 +08:00
										 |  |  | 		this.externalType = type; | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | 		/** @type {string} */ | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.userRequest = userRequest; | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {Set<string>} types availiable (do not mutate) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getSourceTypes() { | 
					
						
							|  |  |  | 		return TYPES; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-07-20 22:24:35 +08:00
										 |  |  | 	 * @param {LibIdentOptions} options options | 
					
						
							|  |  |  | 	 * @returns {string | null} an identifier for library inclusion | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-07-20 22:24:35 +08:00
										 |  |  | 	libIdent(options) { | 
					
						
							| 
									
										
										
										
											2017-06-09 04:22:58 +08:00
										 |  |  | 		return this.userRequest; | 
					
						
							| 
									
										
										
										
											2017-05-18 00:49:09 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk which condition should be checked | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 	 * @param {Compilation} compilation the compilation | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	 * @returns {boolean} true, if the chunk is ok for the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 	chunkCondition(chunk, { chunkGraph }) { | 
					
						
							|  |  |  | 		return chunkGraph.getNumberOfEntryModules(chunk) > 0; | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {string} a unique identifier of the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | 	identifier() { | 
					
						
							|  |  |  | 		return "external " + JSON.stringify(this.request); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {RequestShortener} requestShortener the request shortener | 
					
						
							|  |  |  | 	 * @returns {string} a user readable identifier of the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	readableIdentifier(requestShortener) { | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | 		return "external " + JSON.stringify(this.request); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:38:34 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-09-26 15:14:44 +08:00
										 |  |  | 	 * @param {NeedBuildContext} context context info | 
					
						
							|  |  |  | 	 * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							| 
									
										
										
										
											2018-07-25 18:38:34 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-09-26 15:14:44 +08:00
										 |  |  | 	needBuild(context, callback) { | 
					
						
							|  |  |  | 		return callback(null, !this.buildMeta); | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | 	 * @param {WebpackOptions} options webpack options | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	 * @param {Compilation} compilation the compilation | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | 	 * @param {ResolverWithOptions} resolver the resolver | 
					
						
							|  |  |  | 	 * @param {InputFileSystem} fs the file system | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 	 * @param {function(WebpackError=): void} callback callback function | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | 	build(options, compilation, resolver, fs, callback) { | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 		this.buildMeta = {}; | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 		this.buildInfo = { | 
					
						
							|  |  |  | 			strict: true | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | 		callback(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 	getSourceString(runtimeTemplate, moduleGraph, chunkGraph) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		const request = | 
					
						
							| 
									
										
										
										
											2018-09-18 15:10:14 +08:00
										 |  |  | 			typeof this.request === "object" && !Array.isArray(this.request) | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				? this.request[this.externalType] | 
					
						
							|  |  |  | 				: this.request; | 
					
						
							|  |  |  | 		switch (this.externalType) { | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | 			case "this": | 
					
						
							|  |  |  | 			case "window": | 
					
						
							| 
									
										
										
										
											2017-12-28 01:46:37 +08:00
										 |  |  | 			case "self": | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | 				return getSourceForGlobalVariableExternal(request, this.externalType); | 
					
						
							| 
									
										
										
										
											2017-12-28 01:46:37 +08:00
										 |  |  | 			case "global": | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | 				return getSourceForGlobalVariableExternal( | 
					
						
							| 
									
										
										
										
											2018-04-14 04:40:16 +08:00
										 |  |  | 					request, | 
					
						
							| 
									
										
										
										
											2018-10-18 02:38:00 +08:00
										 |  |  | 					runtimeTemplate.outputOptions.globalObject | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | 			case "commonjs": | 
					
						
							|  |  |  | 			case "commonjs2": | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | 				return getSourceForCommonJsExternal(request); | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | 			case "amd": | 
					
						
							| 
									
										
										
										
											2018-09-27 01:41:22 +08:00
										 |  |  | 			case "amd-require": | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | 			case "umd": | 
					
						
							|  |  |  | 			case "umd2": | 
					
						
							| 
									
										
										
										
											2019-03-02 05:26:36 +08:00
										 |  |  | 			case "system": | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | 				return getSourceForAmdOrUmdExternal( | 
					
						
							| 
									
										
										
										
											2018-08-28 17:56:48 +08:00
										 |  |  | 					chunkGraph.getModuleId(this), | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 					this.isOptional(moduleGraph), | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | 					request, | 
					
						
							|  |  |  | 					runtimeTemplate | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | 			default: | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 				return getSourceForDefaultCase( | 
					
						
							|  |  |  | 					this.isOptional(moduleGraph), | 
					
						
							|  |  |  | 					request, | 
					
						
							|  |  |  | 					runtimeTemplate | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-02-18 21:06:23 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 	 * @param {CodeGenerationContext} context context for code generation | 
					
						
							|  |  |  | 	 * @returns {CodeGenerationResult} result | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 	codeGeneration({ runtimeTemplate, moduleGraph, chunkGraph }) { | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 		const sourceString = this.getSourceString( | 
					
						
							|  |  |  | 			runtimeTemplate, | 
					
						
							|  |  |  | 			moduleGraph, | 
					
						
							|  |  |  | 			chunkGraph | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		const sources = new Map(); | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | 		if (this.useSourceMap) { | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 			sources.set( | 
					
						
							|  |  |  | 				"javascript", | 
					
						
							|  |  |  | 				new OriginalSource(sourceString, this.identifier()) | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 			sources.set("javascript", new RawSource(sourceString)); | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 		return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS }; | 
					
						
							| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-12-04 18:23:40 +08:00
										 |  |  | 	 * @param {string=} type the source type for which the size should be estimated | 
					
						
							| 
									
										
										
										
											2019-05-13 18:29:29 +08:00
										 |  |  | 	 * @returns {number} the estimated size of the module (must be non-zero) | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-12-04 18:23:40 +08:00
										 |  |  | 	size(type) { | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | 		return 42; | 
					
						
							| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-09-18 00:18:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-21 00:17:51 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Hash} hash the hash used to track dependencies | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | 	 * @param {ChunkGraph} chunkGraph the chunk graph | 
					
						
							| 
									
										
										
										
											2018-07-21 00:17:51 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | 	updateHash(hash, chunkGraph) { | 
					
						
							| 
									
										
										
										
											2017-11-10 18:51:29 +08:00
										 |  |  | 		hash.update(this.externalType); | 
					
						
							| 
									
										
										
										
											2017-09-18 00:18:40 +08:00
										 |  |  | 		hash.update(JSON.stringify(this.request)); | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 		hash.update( | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | 			JSON.stringify(Boolean(this.isOptional(chunkGraph.moduleGraph))) | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | 		super.updateHash(hash, chunkGraph); | 
					
						
							| 
									
										
										
										
											2017-09-18 00:18:40 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-10-18 22:02:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	serialize(context) { | 
					
						
							|  |  |  | 		const { write } = context; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		write(this.request); | 
					
						
							|  |  |  | 		write(this.externalType); | 
					
						
							|  |  |  | 		write(this.userRequest); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		super.serialize(context); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	deserialize(context) { | 
					
						
							|  |  |  | 		const { read } = context; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.request = read(); | 
					
						
							|  |  |  | 		this.externalType = read(); | 
					
						
							|  |  |  | 		this.userRequest = read(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		super.deserialize(context); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-18 22:02:45 +08:00
										 |  |  | makeSerializable(ExternalModule, "webpack/lib/ExternalModule"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | module.exports = ExternalModule; |