MCPcopy
hub / github.com/webpack/webpack / _getSourceData

Method _getSourceData

lib/ExternalModule.js:1068–1176  ·  view source on GitHub ↗

* Returns the source data. * @private * @param {string | string[]} request request * @param {ExternalsType} externalType the external type * @param {RuntimeTemplate} runtimeTemplate the runtime template * @param {ModuleGraph} moduleGraph the module graph * @param {ChunkGraph} chunkGraph

(
		request,
		externalType,
		runtimeTemplate,
		moduleGraph,
		chunkGraph,
		runtime,
		dependencyMeta,
		concatenationScope
	)

Source from the content-addressed store, hash-verified

1066 * @returns {SourceData} the source data
1067 */
1068 _getSourceData(
1069 request,
1070 externalType,
1071 runtimeTemplate,
1072 moduleGraph,
1073 chunkGraph,
1074 runtime,
1075 dependencyMeta,
1076 concatenationScope
1077 ) {
1078 request = normalizeNodeCoreModuleRequest(
1079 request,
1080 externalType,
1081 runtimeTemplate
1082 );
1083 switch (externalType) {
1084 case "this":
1085 case "window":
1086 case "self":
1087 return getSourceForGlobalVariableExternal(request, this.externalType);
1088 case "global":
1089 return getSourceForGlobalVariableExternal(
1090 request,
1091 runtimeTemplate.globalObject
1092 );
1093 case "commonjs":
1094 case "commonjs2":
1095 case "commonjs-module":
1096 case "commonjs-static":
1097 case "node-commonjs": {
1098 const { node } = runtimeTemplate.compilation.options.externalsPresets;
1099 // ESM has no `require`; load via `createRequire` when the target is node
1100 const createRequireInModule =
1101 /** @type {BuildInfo} */ (this.buildInfo).javascriptModule &&
1102 (externalType === "node-commonjs" || Boolean(node));
1103 if (!createRequireInModule) {
1104 return getSourceForCommonJsExternal(request);
1105 }
1106 // for a universal target (e.g. `["node", "web"]`) load defensively so the browser doesn't crash
1107 return getSourceForCommonJsExternalInNodeModule(
1108 request,
1109 runtimeTemplate,
1110 runtimeTemplate.isUniversalTarget()
1111 );
1112 }
1113 case "amd":
1114 case "amd-require":
1115 case "umd":
1116 case "umd2":
1117 case "system":
1118 case "jsonp": {
1119 const id = chunkGraph.getModuleId(this);
1120 return getSourceForAmdOrUmdExternal(
1121 id !== null ? id : this.identifier(),
1122 this.isOptional(moduleGraph),
1123 request,
1124 runtimeTemplate
1125 );

Callers 1

codeGenerationMethod · 0.95

Tested by

no test coverage detected