| 
									
										
										
										
											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"); | 
					
						
							| 
									
										
										
										
											2020-09-15 16:56:06 +08:00
										 |  |  | const ConcatenationScope = require("./ConcatenationScope"); | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | const { UsageState } = require("./ExportsInfo"); | 
					
						
							|  |  |  | const InitFragment = require("./InitFragment"); | 
					
						
							| 
									
										
										
										
											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"); | 
					
						
							| 
									
										
										
										
											2020-03-05 20:31:58 +08:00
										 |  |  | const StaticExportsDependency = require("./dependencies/StaticExportsDependency"); | 
					
						
							| 
									
										
										
										
											2020-08-11 20:51:44 +08:00
										 |  |  | const extractUrlAndGlobal = require("./util/extractUrlAndGlobal"); | 
					
						
							| 
									
										
										
										
											2018-10-18 22:02:45 +08:00
										 |  |  | const makeSerializable = require("./util/makeSerializable"); | 
					
						
							| 
									
										
										
										
											2020-02-18 17:44:55 +08:00
										 |  |  | const propertyAccess = require("./util/propertyAccess"); | 
					
						
							| 
									
										
										
										
											2021-07-06 06:18:11 +08:00
										 |  |  | const { register } = require("./util/serialization"); | 
					
						
							| 
									
										
										
										
											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 */ | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */ | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | /** @typedef {import("./DependencyTemplates")} DependencyTemplates */ | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | /** @typedef {import("./ExportsInfo")} ExportsInfo */ | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */ | 
					
						
							|  |  |  | /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */ | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | /** @typedef {import("./Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */ | 
					
						
							| 
									
										
										
										
											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 */ | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | /** @typedef {import("./javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */ | 
					
						
							| 
									
										
										
										
											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 */ | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */ | 
					
						
							| 
									
										
										
										
											2018-07-21 00:17:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} SourceData | 
					
						
							| 
									
										
										
										
											2020-10-20 23:38:29 +08:00
										 |  |  |  * @property {boolean=} iife | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  |  * @property {string=} init | 
					
						
							|  |  |  |  * @property {string} expression | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  |  * @property {InitFragment<ChunkRenderContext>[]=} chunkInitFragments | 
					
						
							|  |  |  |  * @property {ReadonlySet<string>=} runtimeRequirements | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | const TYPES = new Set(["javascript"]); | 
					
						
							|  |  |  | const RUNTIME_REQUIREMENTS = new Set([RuntimeGlobals.module]); | 
					
						
							|  |  |  | const RUNTIME_REQUIREMENTS_FOR_SCRIPT = new Set([RuntimeGlobals.loadScript]); | 
					
						
							|  |  |  | const RUNTIME_REQUIREMENTS_FOR_MODULE = new Set([ | 
					
						
							|  |  |  | 	RuntimeGlobals.definePropertyGetters | 
					
						
							|  |  |  | ]); | 
					
						
							|  |  |  | const EMPTY_RUNTIME_REQUIREMENTS = new Set([]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {string|string[]} variableName the variable name or path | 
					
						
							|  |  |  |  * @param {string} type the module system | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  |  * @returns {SourceData} the generated source | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 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(""); | 
					
						
							| 
									
										
										
										
											2020-10-20 23:38:29 +08:00
										 |  |  | 	return { | 
					
						
							|  |  |  | 		iife: type === "this", | 
					
						
							|  |  |  | 		expression: `${type}${objectLookup}` | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {string|string[]} moduleAndSpecifiers the module request | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  |  * @returns {SourceData} the generated source | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | const getSourceForCommonJsExternal = moduleAndSpecifiers => { | 
					
						
							|  |  |  | 	if (!Array.isArray(moduleAndSpecifiers)) { | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 		return { | 
					
						
							| 
									
										
										
										
											2021-06-24 16:05:37 +08:00
										 |  |  | 			expression: `require(${JSON.stringify(moduleAndSpecifiers)})` | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	const moduleName = moduleAndSpecifiers[0]; | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 	return { | 
					
						
							|  |  |  | 		expression: `require(${JSON.stringify(moduleName)})${propertyAccess( | 
					
						
							|  |  |  | 			moduleAndSpecifiers, | 
					
						
							|  |  |  | 			1 | 
					
						
							| 
									
										
										
										
											2021-06-24 16:05:37 +08:00
										 |  |  | 		)}`
 | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2020-05-15 22:24:11 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-25 17:22:55 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {string|string[]} moduleAndSpecifiers the module request | 
					
						
							|  |  |  |  * @returns {SourceData} the generated source | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const getSourceForCommonJsExternalInNodeModule = moduleAndSpecifiers => { | 
					
						
							|  |  |  | 	const chunkInitFragments = [ | 
					
						
							|  |  |  | 		new InitFragment( | 
					
						
							|  |  |  | 			'import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";\n', | 
					
						
							|  |  |  | 			InitFragment.STAGE_HARMONY_IMPORTS, | 
					
						
							|  |  |  | 			0, | 
					
						
							|  |  |  | 			"external module node-commonjs" | 
					
						
							|  |  |  | 		) | 
					
						
							|  |  |  | 	]; | 
					
						
							|  |  |  | 	if (!Array.isArray(moduleAndSpecifiers)) { | 
					
						
							|  |  |  | 		return { | 
					
						
							|  |  |  | 			expression: `__WEBPACK_EXTERNAL_createRequire(import.meta.url)(${JSON.stringify( | 
					
						
							|  |  |  | 				moduleAndSpecifiers | 
					
						
							|  |  |  | 			)})`,
 | 
					
						
							|  |  |  | 			chunkInitFragments | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	const moduleName = moduleAndSpecifiers[0]; | 
					
						
							|  |  |  | 	return { | 
					
						
							|  |  |  | 		expression: `__WEBPACK_EXTERNAL_createRequire(import.meta.url)(${JSON.stringify( | 
					
						
							|  |  |  | 			moduleName | 
					
						
							|  |  |  | 		)})${propertyAccess(moduleAndSpecifiers, 1)}`,
 | 
					
						
							|  |  |  | 		chunkInitFragments | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-15 22:24:11 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {string|string[]} moduleAndSpecifiers the module request | 
					
						
							|  |  |  |  * @param {RuntimeTemplate} runtimeTemplate the runtime template | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  |  * @returns {SourceData} the generated source | 
					
						
							| 
									
										
										
										
											2020-05-15 22:24:11 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | const getSourceForImportExternal = (moduleAndSpecifiers, runtimeTemplate) => { | 
					
						
							| 
									
										
										
										
											2020-09-12 04:46:59 +08:00
										 |  |  | 	const importName = runtimeTemplate.outputOptions.importFunctionName; | 
					
						
							| 
									
										
										
										
											2020-09-12 04:47:37 +08:00
										 |  |  | 	if (!runtimeTemplate.supportsDynamicImport() && importName === "import") { | 
					
						
							| 
									
										
										
										
											2020-09-09 22:37:53 +08:00
										 |  |  | 		throw new Error( | 
					
						
							|  |  |  | 			"The target environment doesn't support 'import()' so it's not possible to use external type 'import'" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-05-15 22:24:11 +08:00
										 |  |  | 	if (!Array.isArray(moduleAndSpecifiers)) { | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 		return { | 
					
						
							|  |  |  | 			expression: `${importName}(${JSON.stringify(moduleAndSpecifiers)});` | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2020-05-15 22:24:11 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (moduleAndSpecifiers.length === 1) { | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 		return { | 
					
						
							|  |  |  | 			expression: `${importName}(${JSON.stringify(moduleAndSpecifiers[0])});` | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2020-05-15 22:24:11 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	const moduleName = moduleAndSpecifiers[0]; | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 	return { | 
					
						
							|  |  |  | 		expression: `${importName}(${JSON.stringify( | 
					
						
							|  |  |  | 			moduleName | 
					
						
							|  |  |  | 		)}).then(${runtimeTemplate.returningFunction( | 
					
						
							|  |  |  | 			`module${propertyAccess(moduleAndSpecifiers, 1)}`, | 
					
						
							|  |  |  | 			"module" | 
					
						
							|  |  |  | 		)});`
 | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | class ModuleExternalInitFragment extends InitFragment { | 
					
						
							|  |  |  | 	constructor(id, request) { | 
					
						
							|  |  |  | 		const identifier = `__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier( | 
					
						
							|  |  |  | 			`${id}` | 
					
						
							|  |  |  | 		)}__`;
 | 
					
						
							|  |  |  | 		super( | 
					
						
							|  |  |  | 			`import * as ${identifier} from ${JSON.stringify(request)};\n`, | 
					
						
							|  |  |  | 			InitFragment.STAGE_HARMONY_IMPORTS, | 
					
						
							|  |  |  | 			0, | 
					
						
							|  |  |  | 			`external module import ${id}` | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		this._identifier = identifier; | 
					
						
							| 
									
										
										
										
											2021-07-06 06:18:11 +08:00
										 |  |  | 		this._id = id; | 
					
						
							|  |  |  | 		this._request = request; | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	getNamespaceIdentifier() { | 
					
						
							|  |  |  | 		return this._identifier; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-06 06:18:11 +08:00
										 |  |  | register( | 
					
						
							|  |  |  | 	ModuleExternalInitFragment, | 
					
						
							|  |  |  | 	"webpack/lib/ExternalModule", | 
					
						
							|  |  |  | 	"ModuleExternalInitFragment", | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		serialize(obj, { write }) { | 
					
						
							|  |  |  | 			write(obj._id); | 
					
						
							|  |  |  | 			write(obj._request); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		deserialize({ read }) { | 
					
						
							|  |  |  | 			return new ModuleExternalInitFragment(read(), read()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | const generateModuleRemapping = (input, exportsInfo, runtime) => { | 
					
						
							|  |  |  | 	if (exportsInfo.otherExportsInfo.getUsed(runtime) === UsageState.Unused) { | 
					
						
							|  |  |  | 		const properties = []; | 
					
						
							|  |  |  | 		for (const exportInfo of exportsInfo.orderedExports) { | 
					
						
							|  |  |  | 			const used = exportInfo.getUsedName(exportInfo.name, runtime); | 
					
						
							|  |  |  | 			if (!used) continue; | 
					
						
							|  |  |  | 			const nestedInfo = exportInfo.getNestedExportsInfo(); | 
					
						
							|  |  |  | 			if (nestedInfo) { | 
					
						
							|  |  |  | 				const nestedExpr = generateModuleRemapping( | 
					
						
							|  |  |  | 					`${input}${propertyAccess([exportInfo.name])}`, | 
					
						
							|  |  |  | 					nestedInfo | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				if (nestedExpr) { | 
					
						
							|  |  |  | 					properties.push(`[${JSON.stringify(used)}]: y(${nestedExpr})`); | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			properties.push( | 
					
						
							|  |  |  | 				`[${JSON.stringify(used)}]: () => ${input}${propertyAccess([ | 
					
						
							|  |  |  | 					exportInfo.name | 
					
						
							|  |  |  | 				])}`
 | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return `x({ ${properties.join(", ")} })`; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {string|number} id the module id | 
					
						
							|  |  |  |  * @param {string|string[]} moduleAndSpecifiers the module request | 
					
						
							|  |  |  |  * @param {ExportsInfo} exportsInfo exports info of this module | 
					
						
							|  |  |  |  * @param {RuntimeSpec} runtime the runtime | 
					
						
							|  |  |  |  * @returns {SourceData} the generated source | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const getSourceForModuleExternal = ( | 
					
						
							|  |  |  | 	id, | 
					
						
							|  |  |  | 	moduleAndSpecifiers, | 
					
						
							|  |  |  | 	exportsInfo, | 
					
						
							|  |  |  | 	runtime | 
					
						
							|  |  |  | ) => { | 
					
						
							|  |  |  | 	if (!Array.isArray(moduleAndSpecifiers)) | 
					
						
							|  |  |  | 		moduleAndSpecifiers = [moduleAndSpecifiers]; | 
					
						
							|  |  |  | 	const initFragment = new ModuleExternalInitFragment( | 
					
						
							|  |  |  | 		id, | 
					
						
							|  |  |  | 		moduleAndSpecifiers[0] | 
					
						
							|  |  |  | 	); | 
					
						
							|  |  |  | 	const baseAccess = `${initFragment.getNamespaceIdentifier()}${propertyAccess( | 
					
						
							|  |  |  | 		moduleAndSpecifiers, | 
					
						
							|  |  |  | 		1 | 
					
						
							|  |  |  | 	)}`;
 | 
					
						
							|  |  |  | 	const moduleRemapping = generateModuleRemapping( | 
					
						
							|  |  |  | 		baseAccess, | 
					
						
							|  |  |  | 		exportsInfo, | 
					
						
							|  |  |  | 		runtime | 
					
						
							|  |  |  | 	); | 
					
						
							|  |  |  | 	let expression = moduleRemapping || baseAccess; | 
					
						
							|  |  |  | 	return { | 
					
						
							|  |  |  | 		expression, | 
					
						
							|  |  |  | 		init: `var x = y => { var x = {}; ${RuntimeGlobals.definePropertyGetters}(x, y); return x; }\nvar y = x => () => x`, | 
					
						
							|  |  |  | 		runtimeRequirements: moduleRemapping | 
					
						
							|  |  |  | 			? RUNTIME_REQUIREMENTS_FOR_MODULE | 
					
						
							|  |  |  | 			: undefined, | 
					
						
							|  |  |  | 		chunkInitFragments: [initFragment] | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-04 08:06:57 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {string|string[]} urlAndGlobal the script request | 
					
						
							|  |  |  |  * @param {RuntimeTemplate} runtimeTemplate the runtime template | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  |  * @returns {SourceData} the generated source | 
					
						
							| 
									
										
										
										
											2020-06-04 08:06:57 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | const getSourceForScriptExternal = (urlAndGlobal, runtimeTemplate) => { | 
					
						
							|  |  |  | 	if (typeof urlAndGlobal === "string") { | 
					
						
							| 
									
										
										
										
											2020-08-11 20:42:32 +08:00
										 |  |  | 		urlAndGlobal = extractUrlAndGlobal(urlAndGlobal); | 
					
						
							| 
									
										
										
										
											2020-06-04 08:06:57 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	const url = urlAndGlobal[0]; | 
					
						
							|  |  |  | 	const globalName = urlAndGlobal[1]; | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 	return { | 
					
						
							| 
									
										
										
										
											2021-02-11 02:14:50 +08:00
										 |  |  | 		init: "var __webpack_error__ = new Error();", | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 		expression: `new Promise(${runtimeTemplate.basicFunction( | 
					
						
							| 
									
										
										
										
											2020-06-04 08:06:57 +08:00
										 |  |  | 			"resolve, reject", | 
					
						
							|  |  |  | 			[ | 
					
						
							|  |  |  | 				`if(typeof ${globalName} !== "undefined") return resolve();`, | 
					
						
							|  |  |  | 				`${RuntimeGlobals.loadScript}(${JSON.stringify( | 
					
						
							|  |  |  | 					url | 
					
						
							|  |  |  | 				)}, ${runtimeTemplate.basicFunction("event", [ | 
					
						
							|  |  |  | 					`if(typeof ${globalName} !== "undefined") return resolve();`, | 
					
						
							|  |  |  | 					"var errorType = event && (event.type === 'load' ? 'missing' : event.type);", | 
					
						
							|  |  |  | 					"var realSrc = event && event.target && event.target.src;", | 
					
						
							| 
									
										
										
										
											2021-02-11 02:14:50 +08:00
										 |  |  | 					"__webpack_error__.message = 'Loading script failed.\\n(' + errorType + ': ' + realSrc + ')';", | 
					
						
							|  |  |  | 					"__webpack_error__.name = 'ScriptExternalLoadError';", | 
					
						
							|  |  |  | 					"__webpack_error__.type = errorType;", | 
					
						
							|  |  |  | 					"__webpack_error__.request = realSrc;", | 
					
						
							|  |  |  | 					"reject(__webpack_error__);" | 
					
						
							| 
									
										
										
										
											2020-06-04 08:06:57 +08:00
										 |  |  | 				])}, ${JSON.stringify(globalName)});`
 | 
					
						
							|  |  |  | 			] | 
					
						
							|  |  |  | 		)}).then(${runtimeTemplate.returningFunction( | 
					
						
							|  |  |  | 			`${globalName}${propertyAccess(urlAndGlobal, 2)}` | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | 		)})`,
 | 
					
						
							|  |  |  | 		runtimeRequirements: RUNTIME_REQUIREMENTS_FOR_SCRIPT | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2020-06-04 08:06:57 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  |  * @returns {SourceData} the generated source | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | const getSourceForAmdOrUmdExternal = ( | 
					
						
							|  |  |  | 	id, | 
					
						
							|  |  |  | 	optional, | 
					
						
							|  |  |  | 	request, | 
					
						
							|  |  |  | 	runtimeTemplate | 
					
						
							|  |  |  | ) => { | 
					
						
							|  |  |  | 	const externalVariable = `__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier( | 
					
						
							|  |  |  | 		`${id}` | 
					
						
							|  |  |  | 	)}__`;
 | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 	return { | 
					
						
							|  |  |  | 		init: optional | 
					
						
							|  |  |  | 			? checkExternalVariable( | 
					
						
							|  |  |  | 					externalVariable, | 
					
						
							|  |  |  | 					Array.isArray(request) ? request.join(".") : request, | 
					
						
							|  |  |  | 					runtimeTemplate | 
					
						
							|  |  |  | 			  ) | 
					
						
							|  |  |  | 			: undefined, | 
					
						
							|  |  |  | 		expression: externalVariable | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @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 | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  |  * @returns {SourceData} the generated source | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 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]; | 
					
						
							| 
									
										
										
										
											2020-02-18 17:44:55 +08:00
										 |  |  | 	const objectLookup = propertyAccess(request, 1); | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 	return { | 
					
						
							|  |  |  | 		init: optional | 
					
						
							|  |  |  | 			? checkExternalVariable(variableName, request.join("."), runtimeTemplate) | 
					
						
							|  |  |  | 			: undefined, | 
					
						
							|  |  |  | 		expression: `${variableName}${objectLookup}` | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +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
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-03-10 09:59:46 +08:00
										 |  |  | 	 * @returns {Set<string>} types available (do not mutate) | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	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) { | 
					
						
							| 
									
										
										
										
											2020-03-05 20:31:58 +08:00
										 |  |  | 		this.buildMeta = { | 
					
						
							| 
									
										
										
										
											2020-05-15 22:24:11 +08:00
										 |  |  | 			async: false, | 
					
						
							| 
									
										
										
										
											2020-03-05 20:31:58 +08:00
										 |  |  | 			exportsType: undefined | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 		this.buildInfo = { | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | 			strict: true, | 
					
						
							|  |  |  | 			topLevelDeclarations: new Set(), | 
					
						
							|  |  |  | 			module: compilation.outputOptions.module | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | 		const { request, externalType } = this._getRequestAndExternalType(); | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 		this.buildMeta.exportsType = "dynamic"; | 
					
						
							|  |  |  | 		let canMangle = false; | 
					
						
							| 
									
										
										
										
											2020-03-05 20:31:58 +08:00
										 |  |  | 		this.clearDependenciesAndBlocks(); | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | 		switch (externalType) { | 
					
						
							|  |  |  | 			case "this": | 
					
						
							|  |  |  | 				this.buildInfo.strict = false; | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2020-05-15 22:24:11 +08:00
										 |  |  | 			case "system": | 
					
						
							| 
									
										
										
										
											2021-07-02 12:53:30 +08:00
										 |  |  | 				if (!Array.isArray(request) || request.length === 1) { | 
					
						
							|  |  |  | 					this.buildMeta.exportsType = "namespace"; | 
					
						
							|  |  |  | 					canMangle = true; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | 			case "module": | 
					
						
							| 
									
										
										
										
											2021-06-25 17:22:55 +08:00
										 |  |  | 				if (this.buildInfo.module) { | 
					
						
							|  |  |  | 					if (!Array.isArray(request) || request.length === 1) { | 
					
						
							|  |  |  | 						this.buildMeta.exportsType = "namespace"; | 
					
						
							|  |  |  | 						canMangle = true; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					this.buildMeta.async = true; | 
					
						
							|  |  |  | 					if (!Array.isArray(request) || request.length === 1) { | 
					
						
							|  |  |  | 						this.buildMeta.exportsType = "namespace"; | 
					
						
							|  |  |  | 						canMangle = false; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2020-07-08 16:58:20 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-05-15 22:24:11 +08:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | 			case "script": | 
					
						
							| 
									
										
										
										
											2020-05-15 22:24:11 +08:00
										 |  |  | 			case "promise": | 
					
						
							|  |  |  | 				this.buildMeta.async = true; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case "import": | 
					
						
							|  |  |  | 				this.buildMeta.async = true; | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | 				if (!Array.isArray(request) || request.length === 1) { | 
					
						
							| 
									
										
										
										
											2020-05-15 22:24:11 +08:00
										 |  |  | 					this.buildMeta.exportsType = "namespace"; | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 					canMangle = false; | 
					
						
							| 
									
										
										
										
											2020-07-08 16:58:20 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-05-15 22:24:11 +08:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2020-03-05 20:31:58 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 		this.addDependency(new StaticExportsDependency(true, canMangle)); | 
					
						
							| 
									
										
										
										
											2017-02-18 20:17:16 +08:00
										 |  |  | 		callback(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-05 16:58:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ConcatenationBailoutReasonContext} context context | 
					
						
							|  |  |  | 	 * @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getConcatenationBailoutReason({ moduleGraph }) { | 
					
						
							|  |  |  | 		switch (this.externalType) { | 
					
						
							|  |  |  | 			case "amd": | 
					
						
							|  |  |  | 			case "amd-require": | 
					
						
							|  |  |  | 			case "umd": | 
					
						
							|  |  |  | 			case "umd2": | 
					
						
							|  |  |  | 			case "system": | 
					
						
							|  |  |  | 			case "jsonp": | 
					
						
							|  |  |  | 				return `${this.externalType} externals can't be concatenated`; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return undefined; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | 	_getRequestAndExternalType() { | 
					
						
							|  |  |  | 		let { request, externalType } = this; | 
					
						
							|  |  |  | 		if (typeof request === "object" && !Array.isArray(request)) | 
					
						
							|  |  |  | 			request = request[externalType]; | 
					
						
							|  |  |  | 		return { request, externalType }; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_getSourceData(runtimeTemplate, moduleGraph, chunkGraph, runtime) { | 
					
						
							|  |  |  | 		const { request, externalType } = this._getRequestAndExternalType(); | 
					
						
							|  |  |  | 		switch (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": | 
					
						
							| 
									
										
										
										
											2020-02-18 17:44:55 +08:00
										 |  |  | 			case "commonjs-module": | 
					
						
							| 
									
										
										
										
											2018-07-31 03:36:46 +08:00
										 |  |  | 				return getSourceForCommonJsExternal(request); | 
					
						
							| 
									
										
										
										
											2021-06-25 17:22:55 +08:00
										 |  |  | 			case "node-commonjs": | 
					
						
							|  |  |  | 				return this.buildInfo.module | 
					
						
							|  |  |  | 					? getSourceForCommonJsExternalInNodeModule(request) | 
					
						
							|  |  |  | 					: 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": | 
					
						
							| 
									
										
										
										
											2020-02-18 17:44:55 +08:00
										 |  |  | 			case "jsonp": | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 				); | 
					
						
							| 
									
										
										
										
											2020-05-15 22:24:11 +08:00
										 |  |  | 			case "import": | 
					
						
							|  |  |  | 				return getSourceForImportExternal(request, runtimeTemplate); | 
					
						
							| 
									
										
										
										
											2020-06-04 08:06:57 +08:00
										 |  |  | 			case "script": | 
					
						
							|  |  |  | 				return getSourceForScriptExternal(request, runtimeTemplate); | 
					
						
							| 
									
										
										
										
											2020-02-18 17:44:55 +08:00
										 |  |  | 			case "module": | 
					
						
							| 
									
										
										
										
											2021-06-25 17:22:55 +08:00
										 |  |  | 				if (!this.buildInfo.module) { | 
					
						
							|  |  |  | 					if (!runtimeTemplate.supportsDynamicImport()) { | 
					
						
							|  |  |  | 						throw new Error( | 
					
						
							|  |  |  | 							"The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script" + | 
					
						
							|  |  |  | 								(runtimeTemplate.supportsEcmaScriptModuleSyntax() | 
					
						
							|  |  |  | 									? "\nDid you mean to build a EcmaScript Module ('output.module: true')?" | 
					
						
							|  |  |  | 									: "") | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					return getSourceForImportExternal(request, runtimeTemplate); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-09-09 22:37:53 +08:00
										 |  |  | 				if (!runtimeTemplate.supportsEcmaScriptModuleSyntax()) { | 
					
						
							|  |  |  | 					throw new Error( | 
					
						
							|  |  |  | 						"The target environment doesn't support EcmaScriptModule syntax so it's not possible to use external type 'module'" | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | 				return getSourceForModuleExternal( | 
					
						
							|  |  |  | 					chunkGraph.getModuleId(this), | 
					
						
							|  |  |  | 					request, | 
					
						
							|  |  |  | 					moduleGraph.getExportsInfo(this), | 
					
						
							|  |  |  | 					runtime | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2020-02-18 17:44:55 +08:00
										 |  |  | 			case "var": | 
					
						
							| 
									
										
										
										
											2020-05-15 22:24:11 +08:00
										 |  |  | 			case "promise": | 
					
						
							| 
									
										
										
										
											2020-02-20 03:25:49 +08:00
										 |  |  | 			case "const": | 
					
						
							|  |  |  | 			case "let": | 
					
						
							| 
									
										
										
										
											2020-02-18 17:44:55 +08:00
										 |  |  | 			case "assign": | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 	codeGeneration({ | 
					
						
							|  |  |  | 		runtimeTemplate, | 
					
						
							|  |  |  | 		moduleGraph, | 
					
						
							|  |  |  | 		chunkGraph, | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | 		runtime, | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 		concatenationScope | 
					
						
							|  |  |  | 	}) { | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | 		const sourceData = this._getSourceData( | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 			runtimeTemplate, | 
					
						
							|  |  |  | 			moduleGraph, | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | 			chunkGraph, | 
					
						
							|  |  |  | 			runtime | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 23:38:29 +08:00
										 |  |  | 		let sourceString = sourceData.expression; | 
					
						
							|  |  |  | 		if (sourceData.iife) | 
					
						
							|  |  |  | 			sourceString = `(function() { return ${sourceString}; }())`; | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 		if (concatenationScope) { | 
					
						
							| 
									
										
										
										
											2020-09-15 16:56:06 +08:00
										 |  |  | 			sourceString = `${runtimeTemplate.supportsConst() ? "const" : "var"} ${ | 
					
						
							|  |  |  | 				ConcatenationScope.NAMESPACE_OBJECT_EXPORT | 
					
						
							| 
									
										
										
										
											2020-10-20 23:38:29 +08:00
										 |  |  | 			} = ${sourceString};`;
 | 
					
						
							| 
									
										
										
										
											2020-09-15 17:43:06 +08:00
										 |  |  | 			concatenationScope.registerNamespaceExport( | 
					
						
							|  |  |  | 				ConcatenationScope.NAMESPACE_OBJECT_EXPORT | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2020-10-20 23:38:29 +08:00
										 |  |  | 			sourceString = `module.exports = ${sourceString};`; | 
					
						
							| 
									
										
										
										
											2020-09-15 16:07:04 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (sourceData.init) sourceString = `${sourceData.init}\n${sourceString}`; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | 		let data = undefined; | 
					
						
							|  |  |  | 		if (sourceData.chunkInitFragments) { | 
					
						
							|  |  |  | 			data = new Map(); | 
					
						
							|  |  |  | 			data.set("chunkInitFragments", sourceData.chunkInitFragments); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 		const sources = new Map(); | 
					
						
							| 
									
										
										
										
											2020-10-26 21:41:46 +08:00
										 |  |  | 		if (this.useSourceMap || this.useSimpleSourceMap) { | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | 		let runtimeRequirements = sourceData.runtimeRequirements; | 
					
						
							|  |  |  | 		if (!concatenationScope) { | 
					
						
							|  |  |  | 			if (!runtimeRequirements) { | 
					
						
							|  |  |  | 				runtimeRequirements = RUNTIME_REQUIREMENTS; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				const set = new Set(runtimeRequirements); | 
					
						
							|  |  |  | 				set.add(RuntimeGlobals.module); | 
					
						
							|  |  |  | 				runtimeRequirements = set; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-04 08:06:57 +08:00
										 |  |  | 		return { | 
					
						
							|  |  |  | 			sources, | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | 			runtimeRequirements: runtimeRequirements || EMPTY_RUNTIME_REQUIREMENTS, | 
					
						
							|  |  |  | 			data | 
					
						
							| 
									
										
										
										
											2020-06-04 08:06:57 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 	 * @param {UpdateHashContext} context context | 
					
						
							| 
									
										
										
										
											2018-07-21 00:17:51 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 	updateHash(hash, context) { | 
					
						
							|  |  |  | 		const { chunkGraph } = context; | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 		super.updateHash(hash, context); | 
					
						
							| 
									
										
										
										
											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; |