webpack 5.108.4 → 5.109.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/lib/APIPlugin.js +48 -29
  2. package/lib/CacheFacade.js +8 -0
  3. package/lib/ChunkGroup.js +1 -0
  4. package/lib/CompatibilityPlugin.js +31 -29
  5. package/lib/Compilation.js +49 -4
  6. package/lib/ConstPlugin.js +11 -11
  7. package/lib/ContextModule.js +239 -6
  8. package/lib/ContextModuleFactory.js +139 -14
  9. package/lib/DefinePlugin.js +396 -101
  10. package/lib/Entrypoint.js +1 -1
  11. package/lib/ExportsInfoApiPlugin.js +2 -2
  12. package/lib/ExternalModule.js +107 -5
  13. package/lib/ExternalModuleFactoryPlugin.js +20 -1
  14. package/lib/FileSystemInfo.js +130 -74
  15. package/lib/HotModuleReplacementPlugin.js +18 -15
  16. package/lib/Module.js +3 -0
  17. package/lib/ModuleFilenameHelpers.js +2 -2
  18. package/lib/ModuleTypeConstants.js +8 -1
  19. package/lib/MultiCompiler.js +13 -2
  20. package/lib/MultiWatching.js +1 -0
  21. package/lib/NodeStuffPlugin.js +51 -33
  22. package/lib/NormalModule.js +169 -401
  23. package/lib/NormalModuleFactory.js +76 -2
  24. package/lib/ProgressPlugin.js +211 -119
  25. package/lib/ProvidePlugin.js +2 -2
  26. package/lib/RuntimeGlobals.js +47 -0
  27. package/lib/RuntimePlugin.js +33 -0
  28. package/lib/RuntimeTemplate.js +304 -16
  29. package/lib/UseStrictPlugin.js +1 -1
  30. package/lib/WebpackIsIncludedPlugin.js +1 -1
  31. package/lib/WebpackOptionsApply.js +24 -19
  32. package/lib/asset/AssetGenerator.js +110 -28
  33. package/lib/asset/AssetModulesPlugin.js +92 -2
  34. package/lib/asset/WebManifestGenerator.js +164 -0
  35. package/lib/asset/WebManifestParser.js +130 -0
  36. package/lib/async-modules/AwaitDependenciesInitFragment.js +14 -4
  37. package/lib/async-modules/isGeneratorLowered.js +26 -0
  38. package/lib/cache/PackFileCacheStrategy.js +9 -3
  39. package/lib/config/browserslistTargetHandler.js +40 -0
  40. package/lib/config/defaults.js +219 -29
  41. package/lib/config/normalization.js +26 -0
  42. package/lib/config/target.js +9 -1
  43. package/lib/css/CssGenerator.js +40 -31
  44. package/lib/css/CssLoadingRuntimeModule.js +5 -1
  45. package/lib/css/CssModulesPlugin.js +13 -0
  46. package/lib/css/CssParser.js +594 -263
  47. package/lib/css/syntax.js +875 -462
  48. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -6
  49. package/lib/dependencies/AMDPlugin.js +2 -2
  50. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +13 -13
  51. package/lib/dependencies/CommonJsDependencyHelpers.js +39 -0
  52. package/lib/dependencies/CommonJsExportsDependency.js +47 -2
  53. package/lib/dependencies/CommonJsExportsParserPlugin.js +10 -10
  54. package/lib/dependencies/CommonJsImportsParserPlugin.js +18 -18
  55. package/lib/dependencies/CommonJsPlugin.js +2 -2
  56. package/lib/dependencies/CommonJsRequireDependency.js +26 -1
  57. package/lib/dependencies/CommonJsSelfReferenceDependency.js +32 -1
  58. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  59. package/lib/dependencies/CreateRequireParserPlugin.js +6 -6
  60. package/lib/dependencies/CssIcssExportDependency.js +162 -71
  61. package/lib/dependencies/CssUrlDependency.js +35 -4
  62. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +2 -2
  63. package/lib/dependencies/HarmonyCompatibilityDependency.js +32 -14
  64. package/lib/dependencies/HarmonyDetectionParserPlugin.js +43 -13
  65. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +7 -19
  66. package/lib/dependencies/HarmonyImportDependency.js +12 -1
  67. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +11 -11
  68. package/lib/dependencies/HarmonyModulesPlugin.js +6 -0
  69. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -1
  70. package/lib/dependencies/HtmlEntryDependency.js +797 -172
  71. package/lib/dependencies/HtmlSourceDependency.js +26 -0
  72. package/lib/dependencies/ImportDependency.js +43 -1
  73. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +31 -18
  74. package/lib/dependencies/ImportMetaContextPlugin.js +38 -7
  75. package/lib/dependencies/ImportMetaGlobDependency.js +81 -0
  76. package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +78 -0
  77. package/lib/dependencies/ImportMetaGlobHelpers.js +660 -0
  78. package/lib/dependencies/ImportMetaPlugin.js +532 -180
  79. package/lib/dependencies/ImportMetaResolveDependency.js +90 -0
  80. package/lib/dependencies/ImportParserPlugin.js +80 -17
  81. package/lib/dependencies/ImportPhase.js +10 -8
  82. package/lib/dependencies/LoaderPlugin.js +5 -1
  83. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  84. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +3 -6
  85. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +4 -11
  86. package/lib/dependencies/SystemPlugin.js +2 -4
  87. package/lib/dependencies/TopLevelAwaitDependency.js +93 -0
  88. package/lib/dependencies/URLDependency.js +141 -21
  89. package/lib/dependencies/{WorkerPlugin.js → WorkerAndWorkletPlugin.js} +324 -112
  90. package/lib/dependencies/WorkerDependency.js +86 -18
  91. package/lib/dependencies/WorkletDependency.js +278 -0
  92. package/lib/dll/DelegatedModuleFactoryPlugin.js +19 -0
  93. package/lib/errors/EnvironmentNotSupportAsyncWarning.js +1 -1
  94. package/lib/errors/LoaderLoadingError.js +20 -0
  95. package/lib/errors/ModuleParseError.js +39 -22
  96. package/lib/errors/NodeStuffInWebError.js +1 -1
  97. package/lib/esm/ModuleChunkFormatPlugin.js +47 -14
  98. package/lib/esm/ModuleChunkLoadingPlugin.js +8 -1
  99. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +29 -1
  100. package/lib/hmr/lazyCompilationBackend.js +32 -8
  101. package/lib/html/HtmlGenerator.js +887 -15
  102. package/lib/html/HtmlModule.js +2 -2
  103. package/lib/html/HtmlModulesPlugin.js +610 -166
  104. package/lib/html/HtmlParser.js +603 -247
  105. package/lib/html/favicon.svg +1 -0
  106. package/lib/html/syntax.js +1264 -661
  107. package/lib/ids/IdHelpers.js +1 -1
  108. package/lib/index.js +6 -0
  109. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -5
  110. package/lib/javascript/BasicEvaluatedExpression.js +366 -48
  111. package/lib/javascript/JavascriptGenerator.js +197 -49
  112. package/lib/javascript/JavascriptModulesPlugin.js +178 -24
  113. package/lib/javascript/JavascriptParser.js +701 -355
  114. package/lib/javascript/JavascriptParserHelpers.js +3 -6
  115. package/lib/javascript/syntax.js +4380 -0
  116. package/lib/library/ModuleLibraryPlugin.js +38 -1
  117. package/lib/loaders/LoaderRunner.js +714 -0
  118. package/lib/loaders/loadLoader.js +100 -0
  119. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +19 -0
  120. package/lib/node/ReadFileCompileWasmPlugin.js +14 -0
  121. package/lib/optimize/ConcatenatedModule.js +120 -16
  122. package/lib/optimize/FlagIncludedChunksPlugin.js +13 -3
  123. package/lib/optimize/InnerGraphPlugin.js +50 -30
  124. package/lib/optimize/ModuleConcatenationPlugin.js +69 -3
  125. package/lib/optimize/SideEffectsFlagPlugin.js +86 -43
  126. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +15 -0
  127. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +24 -13
  128. package/lib/prefetch/ResourceHintPlugin.js +663 -0
  129. package/lib/prefetch/ResourceHintRuntimeModule.js +149 -0
  130. package/lib/prefetch/StartupAssetHintRuntimeModule.js +210 -0
  131. package/lib/prefetch/parseResourceHintOptions.js +103 -0
  132. package/lib/rules/RuleSetCompiler.js +114 -0
  133. package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +56 -0
  134. package/lib/runtime/AsyncModuleRuntimeModule.js +24 -8
  135. package/lib/runtime/AutoPublicPathRuntimeModule.js +7 -1
  136. package/lib/runtime/CommonJsWrapRuntimeModule.js +37 -0
  137. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +59 -0
  138. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +204 -8
  139. package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +4 -1
  140. package/lib/schemes/HttpUriPlugin.js +40 -1
  141. package/lib/schemes/VirtualUrlPlugin.js +1 -2
  142. package/lib/serialization/FileMiddleware.js +29 -3
  143. package/lib/stats/DefaultStatsFactoryPlugin.js +32 -3
  144. package/lib/stats/DefaultStatsPresetPlugin.js +2 -0
  145. package/lib/stats/DefaultStatsPrinterPlugin.js +12 -2
  146. package/lib/stats/StatsFactory.js +15 -8
  147. package/lib/url/URLParserPlugin.js +66 -13
  148. package/lib/util/AsyncQueue.js +122 -72
  149. package/lib/util/SetHelpers.js +1 -1
  150. package/lib/util/StackedMap.js +122 -48
  151. package/lib/util/binarySearchBounds.js +2 -2
  152. package/lib/util/concatenate.js +40 -14
  153. package/lib/util/createHooksRegistry.js +13 -5
  154. package/lib/util/dataURL.js +2 -2
  155. package/lib/util/deterministicGrouping.js +7 -5
  156. package/lib/util/formatSize.js +6 -2
  157. package/lib/util/globUtils.js +710 -0
  158. package/lib/util/identifier.js +23 -6
  159. package/lib/util/implicitTypeLoaderFallback.js +62 -0
  160. package/lib/util/internalSerializables.js +88 -71
  161. package/lib/util/magicComment.js +121 -25
  162. package/lib/util/numberHash.js +2 -2
  163. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +24 -18
  164. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +33 -22
  165. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +79 -16
  166. package/lib/web/FetchCompileAsyncWasmPlugin.js +19 -0
  167. package/lib/web/FetchCompileWasmPlugin.js +14 -0
  168. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -0
  169. package/lib/webpack.js +65 -0
  170. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +3 -0
  171. package/module.d.ts +21 -0
  172. package/package.json +13 -12
  173. package/schemas/WebpackOptions.check.js +1 -1
  174. package/schemas/WebpackOptions.json +759 -36
  175. package/schemas/plugins/HtmlParserOptions.check.js +1 -1
  176. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  177. package/schemas/plugins/ProgressPlugin.json +17 -1
  178. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  179. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  180. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  181. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  182. package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
  183. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
  184. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  185. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  186. package/types.d.ts +1213 -96
@@ -21,6 +21,7 @@ const {
21
21
  const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
22
22
  const RuntimeGlobals = require("./RuntimeGlobals");
23
23
  const Template = require("./Template");
24
+ const WebpackError = require("./WebpackError");
24
25
  const { DEFAULTS } = require("./config/defaults");
25
26
  const { ImportPhaseUtils } = require("./dependencies/ImportPhase");
26
27
  const StaticExportsDependency = require("./dependencies/StaticExportsDependency");
@@ -67,8 +68,9 @@ const { register } = require("./util/serialization");
67
68
  /** @typedef {import("./javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
68
69
  /** @typedef {import("./javascript/JavascriptParser").ImportAttributes} ImportAttributes */
69
70
  /** @typedef {import("./dependencies/ImportPhase").ImportPhaseType} ImportPhaseType */
70
- /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext<[ExternalModuleRequest, ExternalsType, string, DependencyMeta | undefined]>} ObjectDeserializerContext */
71
- /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext<[ExternalModuleRequest, ExternalsType, string, DependencyMeta | undefined]>} ObjectSerializerContext */
71
+ /** @typedef {import("../declarations/WebpackOptions").ExternalItemInterop} ExternalInterop */
72
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext<[ExternalModuleRequest, ExternalsType, string, DependencyMeta | undefined, ExternalInterop | undefined]>} ObjectDeserializerContext */
73
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext<[ExternalModuleRequest, ExternalsType, string, DependencyMeta | undefined, ExternalInterop | undefined]>} ObjectSerializerContext */
72
74
  /** @typedef {import("./util/Hash")} Hash */
73
75
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
74
76
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
@@ -104,6 +106,16 @@ const RUNTIME_REQUIREMENTS_FOR_MODULE = new Set([
104
106
  const EMPTY_RUNTIME_REQUIREMENTS = new Set();
105
107
 
106
108
  const NODE_PREFIX = "node:";
109
+
110
+ // externals of these types are wired by the library wrapper, which does its own per-key lookup on object externals
111
+ const LIBRARY_WIRED_EXTERNAL_TYPES = new Set([
112
+ "amd",
113
+ "amd-require",
114
+ "umd",
115
+ "umd2",
116
+ "system",
117
+ "jsonp"
118
+ ]);
107
119
  // External types that emit a node.js-resolvable specifier (`require`/`import`).
108
120
  const NODE_RESOLVING_EXTERNAL_TYPES = new Set([
109
121
  "commonjs",
@@ -685,6 +697,7 @@ const getSourceForScriptExternal = (urlAndGlobal, runtimeTemplate) => {
685
697
  "__webpack_error__.name = 'ScriptExternalLoadError';",
686
698
  "__webpack_error__.type = errorType;",
687
699
  "__webpack_error__.request = realSrc;",
700
+ "__webpack_error__.event = event;",
688
701
  "reject(__webpack_error__);"
689
702
  ])}, ${JSON.stringify(globalName)});`
690
703
  ]
@@ -695,6 +708,41 @@ const getSourceForScriptExternal = (urlAndGlobal, runtimeTemplate) => {
695
708
  };
696
709
  };
697
710
 
711
+ /**
712
+ * Gets source for amd-async external. Loads the module at runtime via the
713
+ * asynchronous AMD `require([...])` API and exposes it as an async module,
714
+ * so no AMD library wrapper around the chunk is needed.
715
+ * @param {string | string[]} request the request path
716
+ * @param {RuntimeTemplate} runtimeTemplate the runtime template
717
+ * @returns {SourceData} the generated source
718
+ */
719
+ const getSourceForAmdAsyncExternal = (request, runtimeTemplate) => {
720
+ if (!Array.isArray(request)) {
721
+ request = [request];
722
+ }
723
+ const { library } = runtimeTemplate.outputOptions;
724
+ const amdRequire =
725
+ library && library.amdContainer
726
+ ? `${library.amdContainer}.require`
727
+ : "require";
728
+ return {
729
+ expression: `new Promise(${runtimeTemplate.basicFunction(
730
+ "resolve, reject",
731
+ [
732
+ `if (typeof ${amdRequire} !== "function") return reject(new Error(${JSON.stringify(
733
+ `AMD 'require' is not available to load external module ${request[0]}`
734
+ )}));`,
735
+ `${amdRequire}(${JSON.stringify([
736
+ request[0]
737
+ ])}, ${runtimeTemplate.basicFunction(
738
+ "module",
739
+ `resolve(module${propertyAccess(request, 1)});`
740
+ )}, reject);`
741
+ ]
742
+ )})`
743
+ };
744
+ };
745
+
698
746
  /**
699
747
  * Checks external variable.
700
748
  * @param {string} variableName the variable name to check
@@ -783,8 +831,9 @@ class ExternalModule extends Module {
783
831
  * @param {ExternalsType} type type
784
832
  * @param {string} userRequest user request
785
833
  * @param {DependencyMeta=} dependencyMeta dependency meta
834
+ * @param {ExternalInterop=} interop how the external's exports interoperate with ES module imports
786
835
  */
787
- constructor(request, type, userRequest, dependencyMeta) {
836
+ constructor(request, type, userRequest, dependencyMeta, interop) {
788
837
  super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
789
838
 
790
839
  // Redeclared with the external module specific shape
@@ -800,6 +849,8 @@ class ExternalModule extends Module {
800
849
  this.userRequest = userRequest;
801
850
  /** @type {DependencyMeta=} */
802
851
  this.dependencyMeta = dependencyMeta;
852
+ /** @type {ExternalInterop | undefined} interop shape of the external's exports (undefined = importer-driven default) */
853
+ this.interop = interop;
803
854
  }
804
855
 
805
856
  /**
@@ -871,6 +922,7 @@ class ExternalModule extends Module {
871
922
  id += `|attributes=${JSON.stringify(meta.attributes)}`;
872
923
  }
873
924
  }
925
+ if (this.interop) id += `|interop=${this.interop}`;
874
926
  return id;
875
927
  }
876
928
 
@@ -913,6 +965,28 @@ class ExternalModule extends Module {
913
965
  javascriptModule: compilation.outputOptions.module
914
966
  };
915
967
  const { request, externalType } = this._getRequestAndExternalType();
968
+ if (
969
+ request === undefined &&
970
+ typeof this.request === "object" &&
971
+ !Array.isArray(this.request) &&
972
+ !LIBRARY_WIRED_EXTERNAL_TYPES.has(this.externalType)
973
+ ) {
974
+ this.addError(
975
+ new WebpackError(
976
+ `Missing external configuration for type "${
977
+ this.externalType
978
+ }" in external ${JSON.stringify(
979
+ this.request
980
+ )}. Add a ${JSON.stringify(
981
+ this.externalType
982
+ )} entry to it or set 'output.externalsType'/'output.library.type' to one of: ${Object.keys(
983
+ this.request
984
+ )
985
+ .map((key) => JSON.stringify(key))
986
+ .join(", ")}`
987
+ )
988
+ );
989
+ }
916
990
  this.buildMeta.exportsType = "dynamic";
917
991
  let canMangle = false;
918
992
  this.clearDependenciesAndBlocks();
@@ -961,6 +1035,14 @@ class ExternalModule extends Module {
961
1035
  "external promise"
962
1036
  );
963
1037
  break;
1038
+ case "amd-async":
1039
+ this.buildMeta.async = true;
1040
+ EnvironmentNotSupportAsyncWarning.check(
1041
+ this,
1042
+ compilation.runtimeTemplate,
1043
+ "external amd-async"
1044
+ );
1045
+ break;
964
1046
  case "import":
965
1047
  this.buildMeta.async = true;
966
1048
  EnvironmentNotSupportAsyncWarning.check(
@@ -974,6 +1056,20 @@ class ExternalModule extends Module {
974
1056
  }
975
1057
  break;
976
1058
  }
1059
+ // Opt-in override for how the external's exports interoperate with ESM
1060
+ // imports, independent of the importer's strictness (see Rollup's
1061
+ // `output.interop`). Only meaningful for a single-request external.
1062
+ if (this.interop && (!Array.isArray(request) || request.length === 1)) {
1063
+ if (this.interop === "esModule") {
1064
+ // external already is an ES module namespace: `default` unboxes to `.default`
1065
+ this.buildMeta.exportsType = "namespace";
1066
+ } else {
1067
+ // "default": treat as CommonJS, `default` is the whole exports (Node.js semantics)
1068
+ this.buildMeta.exportsType = "default";
1069
+ this.buildMeta.defaultObject = "redirect";
1070
+ }
1071
+ canMangle = false;
1072
+ }
977
1073
  this.addDependency(new StaticExportsDependency(true, canMangle));
978
1074
  callback();
979
1075
  }
@@ -1110,6 +1206,8 @@ class ExternalModule extends Module {
1110
1206
  runtimeTemplate.isUniversalTarget()
1111
1207
  );
1112
1208
  }
1209
+ case "amd-async":
1210
+ return getSourceForAmdAsyncExternal(request, runtimeTemplate);
1113
1211
  case "amd":
1114
1212
  case "amd-require":
1115
1213
  case "umd":
@@ -1349,6 +1447,7 @@ class ExternalModule extends Module {
1349
1447
  hash.update(`|attributes=${JSON.stringify(meta.attributes)}`);
1350
1448
  }
1351
1449
  }
1450
+ if (this.interop) hash.update(`|interop=${this.interop}`);
1352
1451
  super.updateHash(hash, context);
1353
1452
  }
1354
1453
 
@@ -1361,7 +1460,8 @@ class ExternalModule extends Module {
1361
1460
  .write(this.request)
1362
1461
  .write(this.externalType)
1363
1462
  .write(this.userRequest)
1364
- .write(this.dependencyMeta);
1463
+ .write(this.dependencyMeta)
1464
+ .write(this.interop);
1365
1465
 
1366
1466
  super.serialize(context);
1367
1467
  }
@@ -1378,8 +1478,10 @@ class ExternalModule extends Module {
1378
1478
  this.userRequest = c2.read();
1379
1479
  const c3 = c2.rest;
1380
1480
  this.dependencyMeta = c3.read();
1481
+ const c4 = c3.rest;
1482
+ this.interop = c4.read();
1381
1483
 
1382
- super.deserialize(c3.rest);
1484
+ super.deserialize(c4.rest);
1383
1485
  }
1384
1486
  }
1385
1487
 
@@ -23,6 +23,7 @@ const { cachedSetProperty, resolveByProperty } = require("./util/cleverMerge");
23
23
  /** @typedef {import("../declarations/WebpackOptions").ExternalItemValue} ExternalItemValue */
24
24
  /** @typedef {import("../declarations/WebpackOptions").ExternalItemObjectKnown} ExternalItemObjectKnown */
25
25
  /** @typedef {import("../declarations/WebpackOptions").ExternalItemObjectUnknown} ExternalItemObjectUnknown */
26
+ /** @typedef {import("../declarations/WebpackOptions").ExternalItemInterop} ExternalItemInterop */
26
27
  /** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
27
28
  /** @typedef {import("./Dependency")} Dependency */
28
29
  /** @typedef {import("./ExternalModule").DependencyMeta} DependencyMeta */
@@ -161,6 +162,23 @@ class ExternalModuleFactoryPlugin {
161
162
  }
162
163
  /** @type {ExternalValue} */
163
164
  let externalConfig = value === true ? dependency.request : value;
165
+ // `interop` is a reserved key on the object form, not a target;
166
+ // pull it out so the rest stays a pure externalsType->request map.
167
+ /** @type {ExternalItemInterop | undefined} */
168
+ let interop;
169
+ if (
170
+ typeof externalConfig === "object" &&
171
+ externalConfig !== null &&
172
+ !Array.isArray(externalConfig) &&
173
+ Object.prototype.hasOwnProperty.call(externalConfig, "interop")
174
+ ) {
175
+ const { interop: interopValue, ...rest } =
176
+ /** @type {Record<string, string | string[]> & { interop?: ExternalItemInterop }} */ (
177
+ externalConfig
178
+ );
179
+ interop = interopValue;
180
+ externalConfig = rest;
181
+ }
164
182
  // When no explicit type is specified, extract it from the externalConfig
165
183
  if (type === undefined) {
166
184
  if (
@@ -239,7 +257,8 @@ class ExternalModuleFactoryPlugin {
239
257
  externalConfig,
240
258
  resolvedType,
241
259
  dependency.request,
242
- dependencyMeta
260
+ dependencyMeta,
261
+ interop
243
262
  )
244
263
  );
245
264
  };