@rspack-canary/core 1.6.5-canary-480f74ac-20251120174032 → 1.6.5-canary-1b7f543c-20251121112112

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.
package/dist/index.js CHANGED
@@ -5736,7 +5736,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
5736
5736
  }, applyExperimentsDefaults = (experiments, { development })=>{
5737
5737
  F(experiments, "cache", ()=>development), D(experiments, "futureDefaults", !1), D(experiments, "lazyCompilation", !1), D(experiments, "asyncWebAssembly", experiments.futureDefaults), D(experiments, "css", !!experiments.futureDefaults || void 0), D(experiments, "topLevelAwait", !0), D(experiments, "deferImport", !1), D(experiments, "buildHttp", void 0), experiments.buildHttp && "object" == typeof experiments.buildHttp && D(experiments.buildHttp, "upgrade", !1), D(experiments, "incremental", {}), "object" == typeof experiments.incremental && (D(experiments.incremental, "silent", !0), D(experiments.incremental, "make", !0), D(experiments.incremental, "inferAsyncModules", !0), D(experiments.incremental, "providedExports", !0), D(experiments.incremental, "dependenciesDiagnostics", !0), D(experiments.incremental, "sideEffects", !0), D(experiments.incremental, "buildChunkGraph", !1), D(experiments.incremental, "moduleIds", !0), D(experiments.incremental, "chunkIds", !0), D(experiments.incremental, "modulesHashes", !0), D(experiments.incremental, "modulesCodegen", !0), D(experiments.incremental, "modulesRuntimeRequirements", !0), D(experiments.incremental, "chunksRuntimeRequirements", !0), D(experiments.incremental, "chunksHashes", !0), D(experiments.incremental, "chunksRender", !0), D(experiments.incremental, "emitAssets", !0)), D(experiments, "rspackFuture", {}), D(experiments, "parallelCodeSplitting", !1), D(experiments, "parallelLoader", !1), D(experiments, "useInputFileSystem", !1), D(experiments, "inlineConst", !1), D(experiments, "inlineEnum", !1), D(experiments, "typeReexportsPresence", !1), D(experiments, "lazyBarrel", !0);
5738
5738
  }, applybundlerInfoDefaults = (rspackFuture, library)=>{
5739
- "object" == typeof rspackFuture && (D(rspackFuture, "bundlerInfo", {}), "object" == typeof rspackFuture.bundlerInfo && (D(rspackFuture.bundlerInfo, "version", "1.6.5-canary-480f74ac-20251120174032"), D(rspackFuture.bundlerInfo, "bundler", "rspack"), D(rspackFuture.bundlerInfo, "force", !library)));
5739
+ "object" == typeof rspackFuture && (D(rspackFuture, "bundlerInfo", {}), "object" == typeof rspackFuture.bundlerInfo && (D(rspackFuture.bundlerInfo, "version", "1.6.5-canary-1b7f543c-20251121112112"), D(rspackFuture.bundlerInfo, "bundler", "rspack"), D(rspackFuture.bundlerInfo, "force", !library)));
5740
5740
  }, applySnapshotDefaults = (_snapshot, _env)=>{}, applyModuleDefaults = (module1, { cache, asyncWebAssembly, css, targetProperties, mode, uniqueName, usedExports, inlineConst, deferImport })=>{
5741
5741
  if (assertNotNill(module1.parser), assertNotNill(module1.generator), cache ? D(module1, "unsafeCache", /[\\/]node_modules[\\/]/) : D(module1, "unsafeCache", !1), F(module1.parser, "asset", ()=>({})), assertNotNill(module1.parser.asset), F(module1.parser.asset, "dataUrlCondition", ()=>({})), "object" == typeof module1.parser.asset.dataUrlCondition && D(module1.parser.asset.dataUrlCondition, "maxSize", 8096), F(module1.parser, "javascript", ()=>({})), assertNotNill(module1.parser.javascript), ((parserOptions, { usedExports, inlineConst, deferImport })=>{
5742
5742
  D(parserOptions, "dynamicImportMode", "lazy"), D(parserOptions, "dynamicImportPrefetch", !1), D(parserOptions, "dynamicImportPreload", !1), D(parserOptions, "url", !0), D(parserOptions, "exprContextCritical", !0), D(parserOptions, "unknownContextCritical", !0), D(parserOptions, "wrappedContextCritical", !1), D(parserOptions, "wrappedContextRegExp", /.*/), D(parserOptions, "strictExportPresence", !1), D(parserOptions, "requireAsExpression", !0), D(parserOptions, "requireDynamic", !0), D(parserOptions, "requireResolve", !0), D(parserOptions, "commonjs", !0), D(parserOptions, "importDynamic", !0), D(parserOptions, "worker", [
@@ -7386,7 +7386,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
7386
7386
  });
7387
7387
  }
7388
7388
  }
7389
- let CORE_VERSION = "1.6.5-canary-480f74ac-20251120174032", bindingVersionCheck_errorMessage = (coreVersion, expectedCoreVersion)=>process.env.RSPACK_BINDING ? `Unmatched version @rspack/core@${coreVersion} and binding version.
7389
+ let CORE_VERSION = "1.6.5-canary-1b7f543c-20251121112112", bindingVersionCheck_errorMessage = (coreVersion, expectedCoreVersion)=>process.env.RSPACK_BINDING ? `Unmatched version @rspack/core@${coreVersion} and binding version.
7390
7390
 
7391
7391
  Help:
7392
7392
  Looks like you are using a custom binding (via environment variable 'RSPACK_BINDING=${process.env.RSPACK_BINDING}').
@@ -8686,7 +8686,7 @@ Help:
8686
8686
  obj.children = this.stats.map((stat, idx)=>{
8687
8687
  let obj = stat.toJson(childOptions.children[idx]), compilationName = stat.compilation.name;
8688
8688
  return obj.name = compilationName && makePathsRelative(childOptions.context, compilationName, stat.compilation.compiler.root), obj;
8689
- }), childOptions.version && (obj.rspackVersion = "1.6.5-canary-480f74ac-20251120174032", obj.version = "5.75.0"), childOptions.hash && (obj.hash = obj.children.map((j)=>j.hash).join(""));
8689
+ }), childOptions.version && (obj.rspackVersion = "1.6.5-canary-1b7f543c-20251121112112", obj.version = "5.75.0"), childOptions.hash && (obj.hash = obj.children.map((j)=>j.hash).join(""));
8690
8690
  let mapError = (j, obj)=>({
8691
8691
  ...obj,
8692
8692
  compilerPath: obj.compilerPath ? `${j.name}.${obj.compilerPath}` : j.name
@@ -9585,7 +9585,7 @@ Help:
9585
9585
  object.hash = context.getStatsCompilation(compilation).hash;
9586
9586
  },
9587
9587
  version: (object)=>{
9588
- object.version = "5.75.0", object.rspackVersion = "1.6.5-canary-480f74ac-20251120174032";
9588
+ object.version = "5.75.0", object.rspackVersion = "1.6.5-canary-1b7f543c-20251121112112";
9589
9589
  },
9590
9590
  env: (object, _compilation, _context, { _env })=>{
9591
9591
  object.env = _env;
@@ -11430,30 +11430,116 @@ Help:
11430
11430
  function isRequiredVersion(str) {
11431
11431
  return VERSION_PATTERN_REGEXP.test(str);
11432
11432
  }
11433
- let MANIFEST_FILE_NAME = "mf-manifest.json", STATS_FILE_NAME = "mf-stats.json", JSON_EXT = ".json";
11433
+ let encodeName = function(name, prefix = "", withExt = !1) {
11434
+ return `${prefix}${name.replace(/@/g, "scope_").replace(/-/g, "_").replace(/\//g, "__").replace(/\./g, "")}${withExt ? ".js" : ""}`;
11435
+ }, parseOptions = (options, normalizeSimple, normalizeOptions)=>{
11436
+ let items = [];
11437
+ var options1 = options, normalizeSimple1 = normalizeSimple, normalizeOptions1 = normalizeOptions, fn = (key, value)=>{
11438
+ items.push([
11439
+ key,
11440
+ value
11441
+ ]);
11442
+ };
11443
+ let object = (obj)=>{
11444
+ for (let [key, value] of Object.entries(obj))"string" == typeof value || Array.isArray(value) ? fn(key, normalizeSimple1(value, key)) : fn(key, normalizeOptions1(value, key));
11445
+ };
11446
+ if (options1) if (Array.isArray(options1)) {
11447
+ var items1 = options1;
11448
+ for (let item of items1)if ("string" == typeof item) fn(item, normalizeSimple1(item, item));
11449
+ else if (item && "object" == typeof item) object(item);
11450
+ else throw Error("Unexpected options format");
11451
+ } else if ("object" == typeof options1) object(options1);
11452
+ else throw Error("Unexpected options format");
11453
+ return items;
11454
+ }, MANIFEST_FILE_NAME = "mf-manifest.json", STATS_FILE_NAME = "mf-stats.json", JSON_EXT = ".json";
11434
11455
  function isPlainObject(value) {
11435
11456
  return !!value && "object" == typeof value && !Array.isArray(value);
11436
11457
  }
11458
+ function getFileName(manifestOptions) {
11459
+ var name;
11460
+ if (!manifestOptions) return {
11461
+ statsFileName: STATS_FILE_NAME,
11462
+ manifestFileName: MANIFEST_FILE_NAME
11463
+ };
11464
+ let filePath = "boolean" == typeof manifestOptions ? "" : manifestOptions.filePath || "", fileName = "boolean" == typeof manifestOptions ? "" : manifestOptions.fileName || "", manifestFileName = fileName ? (name = fileName).endsWith(JSON_EXT) ? name : `${name}${JSON_EXT}` : MANIFEST_FILE_NAME, statsFileName = fileName ? manifestFileName.replace(JSON_EXT, `-stats${JSON_EXT}`) : STATS_FILE_NAME;
11465
+ return {
11466
+ statsFileName: (0, external_node_path_namespaceObject.join)(filePath, statsFileName),
11467
+ manifestFileName: (0, external_node_path_namespaceObject.join)(filePath, manifestFileName)
11468
+ };
11469
+ }
11437
11470
  class ModuleFederationManifestPlugin extends RspackBuiltinPlugin {
11438
11471
  name = binding_.BuiltinPluginName.ModuleFederationManifestPlugin;
11439
11472
  opts;
11440
11473
  constructor(opts){
11441
- super(), this.opts = opts;
11474
+ var mfConfig;
11475
+ let manifestOptions, containerName, globalName, remoteAliasMap, manifestExposes, manifestShared;
11476
+ super(), this.opts = (manifestOptions = !0 === (mfConfig = opts).manifest ? {} : {
11477
+ ...mfConfig.manifest
11478
+ }, containerName = mfConfig.name, globalName = function(library) {
11479
+ if (!library) return;
11480
+ let libName = library.name;
11481
+ if (libName) {
11482
+ if ("string" == typeof libName) return libName;
11483
+ if (Array.isArray(libName)) return libName[0];
11484
+ if ("object" == typeof libName) return libName.root?.[0] ?? libName.amd ?? libName.commonjs ?? void 0;
11485
+ }
11486
+ }(mfConfig.library) ?? containerName, remoteAliasMap = Object.entries(getRemoteInfos(mfConfig)).reduce((sum, cur)=>{
11487
+ if (cur[1].length > 1) return sum;
11488
+ let { entry, alias, name } = cur[1][0];
11489
+ return entry && name && (sum[alias] = {
11490
+ name,
11491
+ entry
11492
+ }), sum;
11493
+ }, {}), manifestExposes = function(exposes) {
11494
+ if (!exposes) return;
11495
+ let result = parseOptions(exposes, (value)=>({
11496
+ import: Array.isArray(value) ? value : [
11497
+ value
11498
+ ],
11499
+ name: void 0
11500
+ }), (value)=>({
11501
+ import: Array.isArray(value.import) ? value.import : [
11502
+ value.import
11503
+ ],
11504
+ name: value.name ?? void 0
11505
+ })).map(([exposeKey, info])=>{
11506
+ let exposeName = info.name ?? exposeKey.replace(/^\.\//, "");
11507
+ return {
11508
+ path: exposeKey,
11509
+ name: exposeName
11510
+ };
11511
+ });
11512
+ return result.length > 0 ? result : void 0;
11513
+ }(mfConfig.exposes), void 0 === manifestOptions.exposes && manifestExposes && (manifestOptions.exposes = manifestExposes), manifestShared = function(shared) {
11514
+ if (!shared) return;
11515
+ let result = parseOptions(shared, (item, key)=>{
11516
+ if ("string" != typeof item) throw Error("Unexpected array in shared");
11517
+ return item !== key && isRequiredVersion(item) ? {
11518
+ import: key,
11519
+ requiredVersion: item
11520
+ } : {
11521
+ import: item
11522
+ };
11523
+ }, (item)=>item).map(([key, config])=>{
11524
+ let name = config.shareKey || key, version = "string" == typeof config.version ? config.version : void 0;
11525
+ return {
11526
+ name,
11527
+ version,
11528
+ requiredVersion: "string" == typeof config.requiredVersion ? config.requiredVersion : void 0,
11529
+ singleton: config.singleton
11530
+ };
11531
+ });
11532
+ return result.length > 0 ? result : void 0;
11533
+ }(mfConfig.shared), void 0 === manifestOptions.shared && manifestShared && (manifestOptions.shared = manifestShared), {
11534
+ ...manifestOptions,
11535
+ remoteAliasMap,
11536
+ globalName,
11537
+ name: containerName
11538
+ });
11442
11539
  }
11443
11540
  raw(compiler) {
11444
11541
  var isDev;
11445
- let pkg, buildVersion, { fileName, filePath, disableAssetsAnalyze, remoteAliasMap, exposes, shared } = this.opts, { statsFileName, manifestFileName } = function(manifestOptions) {
11446
- var name;
11447
- if (!manifestOptions) return {
11448
- statsFileName: STATS_FILE_NAME,
11449
- manifestFileName: MANIFEST_FILE_NAME
11450
- };
11451
- let filePath = "boolean" == typeof manifestOptions ? "" : manifestOptions.filePath || "", fileName = "boolean" == typeof manifestOptions ? "" : manifestOptions.fileName || "", manifestFileName = fileName ? (name = fileName).endsWith(JSON_EXT) ? name : `${name}${JSON_EXT}` : MANIFEST_FILE_NAME, statsFileName = fileName ? manifestFileName.replace(JSON_EXT, `-stats${JSON_EXT}`) : STATS_FILE_NAME;
11452
- return {
11453
- statsFileName: (0, external_node_path_namespaceObject.join)(filePath, statsFileName),
11454
- manifestFileName: (0, external_node_path_namespaceObject.join)(filePath, manifestFileName)
11455
- };
11456
- }(this.opts), rawOptions = {
11542
+ let pkg, buildVersion, { fileName, filePath, disableAssetsAnalyze, remoteAliasMap, exposes, shared } = this.opts, { statsFileName, manifestFileName } = getFileName(this.opts), rawOptions = {
11457
11543
  name: this.opts.name,
11458
11544
  globalName: this.opts.globalName,
11459
11545
  fileName,
@@ -11488,81 +11574,6 @@ Help:
11488
11574
  return createBuiltinPlugin(this.name, rawOptions);
11489
11575
  }
11490
11576
  }
11491
- let ModuleFederationRuntimePlugin = base_create(binding_.BuiltinPluginName.ModuleFederationRuntimePlugin, (options = {})=>options), parseOptions = (options, normalizeSimple, normalizeOptions)=>{
11492
- let items = [];
11493
- var options1 = options, normalizeSimple1 = normalizeSimple, normalizeOptions1 = normalizeOptions, fn = (key, value)=>{
11494
- items.push([
11495
- key,
11496
- value
11497
- ]);
11498
- };
11499
- let object = (obj)=>{
11500
- for (let [key, value] of Object.entries(obj))"string" == typeof value || Array.isArray(value) ? fn(key, normalizeSimple1(value, key)) : fn(key, normalizeOptions1(value, key));
11501
- };
11502
- if (options1) if (Array.isArray(options1)) {
11503
- var items1 = options1;
11504
- for (let item of items1)if ("string" == typeof item) fn(item, normalizeSimple1(item, item));
11505
- else if (item && "object" == typeof item) object(item);
11506
- else throw Error("Unexpected options format");
11507
- } else if ("object" == typeof options1) object(options1);
11508
- else throw Error("Unexpected options format");
11509
- return items;
11510
- };
11511
- function getRemoteInfos(options) {
11512
- if (!options.remotes) return {};
11513
- let remoteType = options.remoteType || (options.library ? options.library.type : "script"), remotes = parseOptions(options.remotes, (item)=>({
11514
- external: Array.isArray(item) ? item : [
11515
- item
11516
- ],
11517
- shareScope: options.shareScope || "default"
11518
- }), (item)=>({
11519
- external: Array.isArray(item.external) ? item.external : [
11520
- item.external
11521
- ],
11522
- shareScope: item.shareScope || options.shareScope || "default"
11523
- })), remoteInfos = {};
11524
- for (let [key, config] of remotes)for (let external of config.external){
11525
- let [externalType, externalRequest] = function(external) {
11526
- let result = function(external) {
11527
- if (/^[a-z0-9-]+ /.test(external)) {
11528
- let idx = external.indexOf(" ");
11529
- return [
11530
- external.slice(0, idx),
11531
- external.slice(idx + 1)
11532
- ];
11533
- }
11534
- return null;
11535
- }(external);
11536
- return null === result ? [
11537
- remoteType,
11538
- external
11539
- ] : result;
11540
- }(external);
11541
- if (remoteInfos[key] ??= [], "script" === externalType) {
11542
- let [url, global] = function(urlAndGlobal) {
11543
- let index = urlAndGlobal.indexOf("@");
11544
- return index <= 0 || index === urlAndGlobal.length - 1 ? null : [
11545
- urlAndGlobal.substring(index + 1),
11546
- urlAndGlobal.substring(0, index)
11547
- ];
11548
- }(externalRequest);
11549
- remoteInfos[key].push({
11550
- alias: key,
11551
- name: global,
11552
- entry: url,
11553
- externalType,
11554
- shareScope: config.shareScope
11555
- });
11556
- } else remoteInfos[key].push({
11557
- alias: key,
11558
- name: void 0,
11559
- entry: void 0,
11560
- externalType,
11561
- shareScope: config.shareScope
11562
- });
11563
- }
11564
- return remoteInfos;
11565
- }
11566
11577
  let compilerSet = new WeakSet();
11567
11578
  class ShareRuntimePlugin extends RspackBuiltinPlugin {
11568
11579
  enhanced;
@@ -11575,42 +11586,45 @@ Help:
11575
11586
  if (compiler1 = compiler, !compilerSet.has(compiler1)) return compiler2 = compiler, compilerSet.add(compiler2), createBuiltinPlugin(this.name, this.enhanced);
11576
11587
  }
11577
11588
  }
11589
+ function normalizeConsumeShareOptions(consumes, shareScope) {
11590
+ return parseOptions(consumes, (item, key)=>{
11591
+ if (Array.isArray(item)) throw Error("Unexpected array in options");
11592
+ return item !== key && isRequiredVersion(item) ? {
11593
+ import: key,
11594
+ shareScope: shareScope || "default",
11595
+ shareKey: key,
11596
+ requiredVersion: item,
11597
+ strictVersion: !0,
11598
+ packageName: void 0,
11599
+ singleton: !1,
11600
+ eager: !1
11601
+ } : {
11602
+ import: key,
11603
+ shareScope: shareScope || "default",
11604
+ shareKey: key,
11605
+ requiredVersion: void 0,
11606
+ packageName: void 0,
11607
+ strictVersion: !1,
11608
+ singleton: !1,
11609
+ eager: !1
11610
+ };
11611
+ }, (item, key)=>({
11612
+ import: !1 === item.import ? void 0 : item.import || key,
11613
+ shareScope: item.shareScope || shareScope || "default",
11614
+ shareKey: item.shareKey || key,
11615
+ requiredVersion: item.requiredVersion,
11616
+ strictVersion: "boolean" == typeof item.strictVersion ? item.strictVersion : !1 !== item.import && !item.singleton,
11617
+ packageName: item.packageName,
11618
+ singleton: !!item.singleton,
11619
+ eager: !!item.eager
11620
+ }));
11621
+ }
11578
11622
  class ConsumeSharedPlugin extends RspackBuiltinPlugin {
11579
11623
  name = binding_.BuiltinPluginName.ConsumeSharedPlugin;
11580
11624
  _options;
11581
11625
  constructor(options){
11582
11626
  super(), this._options = {
11583
- consumes: parseOptions(options.consumes, (item, key)=>{
11584
- if (Array.isArray(item)) throw Error("Unexpected array in options");
11585
- return item !== key && isRequiredVersion(item) ? {
11586
- import: key,
11587
- shareScope: options.shareScope || "default",
11588
- shareKey: key,
11589
- requiredVersion: item,
11590
- strictVersion: !0,
11591
- packageName: void 0,
11592
- singleton: !1,
11593
- eager: !1
11594
- } : {
11595
- import: key,
11596
- shareScope: options.shareScope || "default",
11597
- shareKey: key,
11598
- requiredVersion: void 0,
11599
- packageName: void 0,
11600
- strictVersion: !1,
11601
- singleton: !1,
11602
- eager: !1
11603
- };
11604
- }, (item, key)=>({
11605
- import: !1 === item.import ? void 0 : item.import || key,
11606
- shareScope: item.shareScope || options.shareScope || "default",
11607
- shareKey: item.shareKey || key,
11608
- requiredVersion: item.requiredVersion,
11609
- strictVersion: "boolean" == typeof item.strictVersion ? item.strictVersion : !1 !== item.import && !item.singleton,
11610
- packageName: item.packageName,
11611
- singleton: !!item.singleton,
11612
- eager: !!item.eager
11613
- })),
11627
+ consumes: normalizeConsumeShareOptions(options.consumes, options.shareScope),
11614
11628
  enhanced: options.enhanced ?? !1
11615
11629
  };
11616
11630
  }
@@ -11626,33 +11640,59 @@ Help:
11626
11640
  return createBuiltinPlugin(this.name, rawOptions);
11627
11641
  }
11628
11642
  }
11643
+ class OptimizeDependencyReferencedExportsPlugin extends RspackBuiltinPlugin {
11644
+ name = binding_.BuiltinPluginName.OptimizeDependencyReferencedExportsPlugin;
11645
+ sharedOptions;
11646
+ injectUsedExports;
11647
+ manifestOptions;
11648
+ constructor(sharedOptions, injectUsedExports, manifestOptions){
11649
+ super(), this.sharedOptions = sharedOptions, this.injectUsedExports = injectUsedExports ?? !0, this.manifestOptions = manifestOptions ?? {};
11650
+ }
11651
+ buildOptions() {
11652
+ let shared = this.sharedOptions.map(([shareKey, config])=>({
11653
+ shareKey,
11654
+ treeshake: !!config.treeshake,
11655
+ usedExports: config.usedExports
11656
+ })), { manifestFileName, statsFileName } = getFileName(this.manifestOptions);
11657
+ return {
11658
+ shared,
11659
+ injectUsedExports: this.injectUsedExports,
11660
+ manifestFileName,
11661
+ statsFileName
11662
+ };
11663
+ }
11664
+ raw() {
11665
+ if (this.sharedOptions.length) return createBuiltinPlugin(this.name, this.buildOptions());
11666
+ }
11667
+ }
11629
11668
  class ProvideSharedPlugin extends RspackBuiltinPlugin {
11630
11669
  name = binding_.BuiltinPluginName.ProvideSharedPlugin;
11631
11670
  _provides;
11632
11671
  _enhanced;
11633
11672
  constructor(options){
11634
- super(), this._provides = parseOptions(options.provides, (item)=>{
11673
+ var options1, shareScope, enhanced;
11674
+ super(), this._provides = (options1 = options.provides, shareScope = options.shareScope, enhanced = options.enhanced, parseOptions(options1, (item)=>{
11635
11675
  if (Array.isArray(item)) throw Error("Unexpected array of provides");
11636
11676
  return {
11637
11677
  shareKey: item,
11638
11678
  version: void 0,
11639
- shareScope: options.shareScope || "default",
11679
+ shareScope: shareScope || "default",
11640
11680
  eager: !1
11641
11681
  };
11642
11682
  }, (item)=>{
11643
11683
  let raw = {
11644
11684
  shareKey: item.shareKey,
11645
11685
  version: item.version,
11646
- shareScope: item.shareScope || options.shareScope || "default",
11686
+ shareScope: item.shareScope || shareScope || "default",
11647
11687
  eager: !!item.eager
11648
11688
  };
11649
- return options.enhanced ? {
11689
+ return enhanced ? {
11650
11690
  ...raw,
11651
11691
  singleton: item.singleton,
11652
11692
  requiredVersion: item.requiredVersion,
11653
11693
  strictVersion: item.strictVersion
11654
11694
  } : raw;
11655
- }), this._enhanced = options.enhanced;
11695
+ })), this._enhanced = options.enhanced;
11656
11696
  }
11657
11697
  raw(compiler) {
11658
11698
  new ShareRuntimePlugin(this._enhanced ?? !1).apply(compiler);
@@ -11663,32 +11703,39 @@ Help:
11663
11703
  return createBuiltinPlugin(this.name, rawOptions);
11664
11704
  }
11665
11705
  }
11706
+ function normalizeSharedOptions(shared) {
11707
+ return parseOptions(shared, (item, key)=>{
11708
+ if ("string" != typeof item) throw Error("Unexpected array in shared");
11709
+ return item !== key && isRequiredVersion(item) ? {
11710
+ import: key,
11711
+ requiredVersion: item
11712
+ } : {
11713
+ import: item
11714
+ };
11715
+ }, (item)=>item);
11716
+ }
11717
+ function createConsumeShareOptions(normalizedSharedOptions) {
11718
+ return normalizedSharedOptions.map(([key, options])=>({
11719
+ [key]: {
11720
+ import: options.import,
11721
+ shareKey: options.shareKey || key,
11722
+ shareScope: options.shareScope,
11723
+ requiredVersion: options.requiredVersion,
11724
+ strictVersion: options.strictVersion,
11725
+ singleton: options.singleton,
11726
+ packageName: options.packageName,
11727
+ eager: options.eager
11728
+ }
11729
+ }));
11730
+ }
11666
11731
  class SharePlugin {
11667
11732
  _shareScope;
11668
11733
  _consumes;
11669
11734
  _provides;
11670
11735
  _enhanced;
11736
+ _sharedOptions;
11671
11737
  constructor(options){
11672
- const sharedOptions = parseOptions(options.shared, (item, key)=>{
11673
- if ("string" != typeof item) throw Error("Unexpected array in shared");
11674
- return item !== key && isRequiredVersion(item) ? {
11675
- import: key,
11676
- requiredVersion: item
11677
- } : {
11678
- import: item
11679
- };
11680
- }, (item)=>item), consumes = sharedOptions.map(([key, options])=>({
11681
- [key]: {
11682
- import: options.import,
11683
- shareKey: options.shareKey || key,
11684
- shareScope: options.shareScope,
11685
- requiredVersion: options.requiredVersion,
11686
- strictVersion: options.strictVersion,
11687
- singleton: options.singleton,
11688
- packageName: options.packageName,
11689
- eager: options.eager
11690
- }
11691
- })), provides = sharedOptions.filter(([, options])=>!1 !== options.import).map(([key, options])=>({
11738
+ const sharedOptions = normalizeSharedOptions(options.shared), consumes = createConsumeShareOptions(sharedOptions), provides = sharedOptions.filter(([, options])=>!1 !== options.import).map(([key, options])=>({
11692
11739
  [options.import || key]: {
11693
11740
  shareKey: options.shareKey || key,
11694
11741
  shareScope: options.shareScope,
@@ -11699,7 +11746,7 @@ Help:
11699
11746
  strictVersion: options.strictVersion
11700
11747
  }
11701
11748
  }));
11702
- this._shareScope = options.shareScope, this._consumes = consumes, this._provides = provides, this._enhanced = options.enhanced ?? !1;
11749
+ this._shareScope = options.shareScope, this._consumes = consumes, this._provides = provides, this._enhanced = options.enhanced ?? !1, this._sharedOptions = sharedOptions;
11703
11750
  }
11704
11751
  apply(compiler) {
11705
11752
  new ConsumeSharedPlugin({
@@ -11711,7 +11758,344 @@ Help:
11711
11758
  provides: this._provides,
11712
11759
  enhanced: this._enhanced
11713
11760
  }).apply(compiler);
11761
+ let treeshakeOptions = this._sharedOptions.filter(([, config])=>config.treeshake);
11762
+ treeshakeOptions.length > 0 && new OptimizeDependencyReferencedExportsPlugin(treeshakeOptions).apply(compiler);
11763
+ }
11764
+ }
11765
+ class CollectShareEntryPlugin extends RspackBuiltinPlugin {
11766
+ name = binding_.BuiltinPluginName.CollectShareEntryPlugin;
11767
+ sharedOptions;
11768
+ _collectedEntries;
11769
+ constructor(options){
11770
+ super();
11771
+ const { sharedOptions } = options;
11772
+ this.sharedOptions = sharedOptions, this._collectedEntries = {};
11714
11773
  }
11774
+ getData() {
11775
+ return this._collectedEntries;
11776
+ }
11777
+ getFilename() {
11778
+ return "collect-share-entries.json";
11779
+ }
11780
+ apply(compiler) {
11781
+ super.apply(compiler), compiler.hooks.thisCompilation.tap("Collect share entry", (compilation)=>{
11782
+ compilation.hooks.processAssets.tapPromise({
11783
+ name: "CollectShareEntry",
11784
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
11785
+ }, async ()=>{
11786
+ let filename = this.getFilename(), asset = compilation.getAsset(filename);
11787
+ if (!asset) throw Error(`Can not get ${filename}`);
11788
+ this._collectedEntries = JSON.parse(asset.source.source().toString()), compilation.deleteAsset(filename);
11789
+ });
11790
+ });
11791
+ }
11792
+ raw() {
11793
+ let rawOptions = {
11794
+ consumes: normalizeConsumeShareOptions(createConsumeShareOptions(this.sharedOptions)).map(([key, v])=>({
11795
+ key,
11796
+ ...v
11797
+ })),
11798
+ filename: this.getFilename()
11799
+ };
11800
+ return createBuiltinPlugin(this.name, rawOptions);
11801
+ }
11802
+ }
11803
+ function assert(condition, msg) {
11804
+ if (!condition) throw Error(msg);
11805
+ }
11806
+ class ShareContainerPlugin extends RspackBuiltinPlugin {
11807
+ name = binding_.BuiltinPluginName.ShareContainerPlugin;
11808
+ filename = "";
11809
+ _options;
11810
+ _shareName;
11811
+ _globalName;
11812
+ constructor(options){
11813
+ super();
11814
+ const { shareName, library, request, independentShareFileName } = options, version = options.version || "0.0.0";
11815
+ this._globalName = encodeName(`${options.mfName}_${shareName}_${version}`);
11816
+ const fileName = independentShareFileName || `${version}/share-entry.js`;
11817
+ this._shareName = shareName, this._options = {
11818
+ name: shareName,
11819
+ request: request,
11820
+ library: (library ? {
11821
+ ...library,
11822
+ name: this._globalName
11823
+ } : void 0) || {
11824
+ type: "var",
11825
+ name: this._globalName
11826
+ },
11827
+ version,
11828
+ fileName
11829
+ };
11830
+ }
11831
+ getData() {
11832
+ return [
11833
+ this.name,
11834
+ this._globalName
11835
+ ];
11836
+ }
11837
+ raw(compiler) {
11838
+ let { library } = this._options;
11839
+ return compiler.options.output.enabledLibraryTypes.includes(library.type) || compiler.options.output.enabledLibraryTypes.push(library.type), createBuiltinPlugin(this.name, this._options);
11840
+ }
11841
+ apply(compiler) {
11842
+ super.apply(compiler);
11843
+ let shareName = this._shareName;
11844
+ compiler.hooks.thisCompilation.tap(this.name, (compilation)=>{
11845
+ compilation.hooks.processAssets.tapPromise({
11846
+ name: "getShareContainerFile"
11847
+ }, async ()=>{
11848
+ assert(compilation.entrypoints.get(shareName), `Can not get shared ${shareName} entryPoint!`);
11849
+ let remoteEntryNameChunk = compilation.namedChunks.get(shareName);
11850
+ assert(remoteEntryNameChunk, `Can not get shared ${shareName} chunk!`);
11851
+ let files = Array.from(remoteEntryNameChunk.files).filter((f)=>!f.includes(".hot-update") && !f.endsWith(".css"));
11852
+ assert(files.length > 0, `no files found for shared ${shareName} chunk`), assert(1 === files.length, `shared ${shareName} chunk should not have multiple files!, current files: ${files.join(",")}`), this.filename = files[0];
11853
+ });
11854
+ });
11855
+ }
11856
+ }
11857
+ let VIRTUAL_ENTRY = "./virtual-entry.js", VIRTUAL_ENTRY_NAME = "virtual-entry";
11858
+ class VirtualEntryPlugin {
11859
+ sharedOptions;
11860
+ constructor(sharedOptions){
11861
+ this.sharedOptions = sharedOptions;
11862
+ }
11863
+ createEntry() {
11864
+ let { sharedOptions } = this;
11865
+ return sharedOptions.reduce((acc, cur, index)=>`${acc}import shared_${index} from '${cur[0]}';\n`, "");
11866
+ }
11867
+ static entry() {
11868
+ return {
11869
+ [VIRTUAL_ENTRY_NAME]: VIRTUAL_ENTRY
11870
+ };
11871
+ }
11872
+ apply(compiler) {
11873
+ new compiler.rspack.experiments.VirtualModulesPlugin({
11874
+ [VIRTUAL_ENTRY]: this.createEntry()
11875
+ }).apply(compiler), compiler.hooks.thisCompilation.tap("RemoveVirtualEntryAsset", (compilation)=>{
11876
+ compilation.hooks.processAssets.tapPromise({
11877
+ name: "RemoveVirtualEntryAsset",
11878
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE
11879
+ }, async ()=>{
11880
+ try {
11881
+ let chunk = compilation.namedChunks.get(VIRTUAL_ENTRY_NAME);
11882
+ chunk?.files.forEach((f)=>{
11883
+ compilation.deleteAsset(f);
11884
+ });
11885
+ } catch (_e) {
11886
+ console.error("Failed to remove virtual entry file!");
11887
+ }
11888
+ });
11889
+ });
11890
+ }
11891
+ }
11892
+ class IndependentSharePlugin {
11893
+ mfName;
11894
+ shared;
11895
+ library;
11896
+ sharedOptions;
11897
+ outputDir;
11898
+ outputFilePath;
11899
+ plugins;
11900
+ compilers = new Map();
11901
+ treeshake;
11902
+ manifest;
11903
+ buildAssets = {};
11904
+ injectUsedExports;
11905
+ name = "IndependentSharePlugin";
11906
+ constructor(options){
11907
+ const { outputDir, outputFilePath, plugins, treeshake, shared, name, manifest, injectUsedExports, library } = options;
11908
+ this.shared = shared, this.mfName = name, this.outputDir = outputFilePath ? "" : outputDir || "independent-packages", this.outputFilePath = outputFilePath, this.plugins = plugins || [], this.treeshake = treeshake, this.manifest = manifest, this.injectUsedExports = injectUsedExports ?? !0, this.library = library, this.sharedOptions = parseOptions(shared, (item, key)=>{
11909
+ if ("string" != typeof item) throw Error(`Unexpected array in shared configuration for key "${key}"`);
11910
+ return item !== key && isRequiredVersion(item) ? {
11911
+ import: key,
11912
+ requiredVersion: item
11913
+ } : {
11914
+ import: item
11915
+ };
11916
+ }, (item)=>item);
11917
+ }
11918
+ apply(compiler) {
11919
+ compiler.hooks.beforeRun.tapAsync("IndependentSharePlugin", async (compiler, callback)=>{
11920
+ await this.createIndependentCompilers(compiler), callback();
11921
+ }), compiler.hooks.shutdown.tapAsync("IndependentSharePlugin", (callback)=>{
11922
+ this.cleanup(), console.log("cleanup"), callback();
11923
+ }), compiler.hooks.compilation.tap("IndependentSharePlugin", (compilation)=>{
11924
+ compilation.hooks.processAssets.tapPromise({
11925
+ name: "injectBuildAssets",
11926
+ stage: compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
11927
+ }, async ()=>{
11928
+ if (!this.manifest) return;
11929
+ let { statsFileName } = getFileName(this.manifest), stats = compilation.getAsset(statsFileName);
11930
+ if (!stats) return;
11931
+ let statsContent = JSON.parse(stats.source.source().toString()), { shared } = statsContent;
11932
+ Object.entries(this.buildAssets).forEach(([key, item])=>{
11933
+ let targetShared = shared.find((s)=>s.name === key);
11934
+ targetShared && item.forEach(([entry, version, globalName])=>{
11935
+ version === targetShared.version && (targetShared.fallback = entry, targetShared.fallbackName = globalName);
11936
+ });
11937
+ }), compilation.updateAsset(statsFileName, new compiler.webpack.sources.RawSource(JSON.stringify(statsContent)));
11938
+ });
11939
+ });
11940
+ }
11941
+ async createIndependentCompilers(parentCompiler) {
11942
+ let { sharedOptions, buildAssets } = this;
11943
+ console.log("🚀 Start creating a standalone compiler...");
11944
+ let parentOutputDir = parentCompiler.options.output.path ? (0, external_node_path_namespaceObject.basename)(parentCompiler.options.output.path) : "", shareRequestsMap = await this.createIndependentCompiler(parentCompiler, parentOutputDir);
11945
+ await Promise.all(sharedOptions.map(async ([shareName, shareConfig])=>{
11946
+ if (!shareConfig.treeshake || !1 === shareConfig.import) return;
11947
+ let shareRequests = shareRequestsMap[shareName].requests;
11948
+ await Promise.all(shareRequests.map(async ([request, version])=>{
11949
+ let sharedConfig = sharedOptions.find(([name])=>name === shareName)?.[1], [shareFileName, globalName] = await this.createIndependentCompiler(parentCompiler, parentOutputDir, {
11950
+ shareRequestsMap,
11951
+ currentShare: {
11952
+ shareName,
11953
+ version,
11954
+ request,
11955
+ independentShareFileName: sharedConfig?.independentShareFileName
11956
+ }
11957
+ });
11958
+ "string" == typeof shareFileName && (buildAssets[shareName] ||= [], buildAssets[shareName].push([
11959
+ shareFileName,
11960
+ version,
11961
+ globalName
11962
+ ]));
11963
+ }));
11964
+ })), console.log("✅ All independent packages have been compiled successfully");
11965
+ }
11966
+ async createIndependentCompiler(parentCompiler, parentOutputDir, extraOptions) {
11967
+ let extraPlugin, { mfName, plugins, outputDir, outputFilePath, sharedOptions, treeshake, library } = this, outputDirWithShareName = outputFilePath || (0, external_node_path_namespaceObject.join)(outputDir, encodeName(extraOptions?.currentShare?.shareName || "")), parentConfig = parentCompiler.options, finalPlugins = [], rspack = parentCompiler.rspack;
11968
+ extraPlugin = extraOptions ? new ShareContainerPlugin({
11969
+ mfName,
11970
+ library,
11971
+ ...extraOptions.currentShare
11972
+ }) : new CollectShareEntryPlugin({
11973
+ sharedOptions,
11974
+ shareScope: "default"
11975
+ }), (parentConfig.plugins || []).forEach((plugin)=>{
11976
+ void 0 !== plugin && "string" != typeof plugin && ((plugin)=>{
11977
+ if (!plugin) return !0;
11978
+ let pluginName = plugin.name || plugin.constructor?.name;
11979
+ return !pluginName || ![
11980
+ "TreeshakeSharePlugin",
11981
+ "IndependentSharePlugin",
11982
+ "ModuleFederationPlugin",
11983
+ "OptimizeDependencyReferencedExportsPlugin",
11984
+ "HtmlWebpackPlugin"
11985
+ ].includes(pluginName);
11986
+ })(plugin) && finalPlugins.push(plugin);
11987
+ }), plugins.forEach((plugin)=>{
11988
+ finalPlugins.push(plugin);
11989
+ }), finalPlugins.push(extraPlugin), finalPlugins.push(new ConsumeSharedPlugin({
11990
+ consumes: sharedOptions.filter(([key, options])=>extraOptions?.currentShare.shareName !== (options.shareKey || key)).map(([key, options])=>({
11991
+ [key]: {
11992
+ import: !!extraOptions && options.import,
11993
+ shareKey: options.shareKey || key,
11994
+ shareScope: options.shareScope,
11995
+ requiredVersion: options.requiredVersion,
11996
+ strictVersion: options.strictVersion,
11997
+ singleton: options.singleton,
11998
+ packageName: options.packageName,
11999
+ eager: options.eager
12000
+ }
12001
+ })),
12002
+ enhanced: !0
12003
+ })), treeshake && finalPlugins.push(new OptimizeDependencyReferencedExportsPlugin(sharedOptions, this.injectUsedExports)), finalPlugins.push(new VirtualEntryPlugin(sharedOptions));
12004
+ let fullOutputDir = (0, external_node_path_namespaceObject.resolve)(parentCompiler.outputPath, outputDirWithShareName), compilerConfig = {
12005
+ ...parentConfig,
12006
+ mode: parentConfig.mode || "development",
12007
+ entry: VirtualEntryPlugin.entry,
12008
+ output: {
12009
+ path: fullOutputDir,
12010
+ clean: !0,
12011
+ publicPath: parentConfig.output?.publicPath || "auto"
12012
+ },
12013
+ plugins: finalPlugins,
12014
+ optimization: {
12015
+ ...parentConfig.optimization,
12016
+ splitChunks: !1
12017
+ }
12018
+ }, compiler = rspack.rspack(compilerConfig);
12019
+ compiler.inputFileSystem = parentCompiler.inputFileSystem, compiler.outputFileSystem = parentCompiler.outputFileSystem, compiler.intermediateFileSystem = parentCompiler.intermediateFileSystem;
12020
+ let { currentShare } = extraOptions || {};
12021
+ return currentShare && this.compilers.set(`${currentShare.shareName}@${currentShare.version}`, compiler), new Promise((resolve, reject)=>{
12022
+ compiler.run((err, stats)=>{
12023
+ if (err || stats?.hasErrors()) {
12024
+ let target = currentShare ? currentShare.shareName : "收集依赖";
12025
+ console.error(`❌ ${target} 编译失败:`, err || stats.toJson().errors.map((e)=>e.message).join("\n")), reject(err || Error(`${target} 编译失败`));
12026
+ return;
12027
+ }
12028
+ currentShare && console.log(`✅ 独立包 ${currentShare.shareName} 编译成功`), stats && (currentShare && console.log(`📊 ${currentShare.shareName} 编译统计:`), console.log(stats.toString({
12029
+ colors: !0,
12030
+ chunks: !1,
12031
+ modules: !1
12032
+ }))), resolve(extraPlugin.getData());
12033
+ });
12034
+ });
12035
+ }
12036
+ cleanup() {
12037
+ this.compilers.forEach((compiler)=>{
12038
+ compiler.watching && compiler.watching.close(()=>{
12039
+ console.log("👋 编译器已关闭");
12040
+ });
12041
+ }), this.compilers.clear();
12042
+ }
12043
+ }
12044
+ let ModuleFederationRuntimePlugin = base_create(binding_.BuiltinPluginName.ModuleFederationRuntimePlugin, (options = {})=>options);
12045
+ function getRemoteInfos(options) {
12046
+ if (!options.remotes) return {};
12047
+ let remoteType = options.remoteType || (options.library ? options.library.type : "script"), remotes = parseOptions(options.remotes, (item)=>({
12048
+ external: Array.isArray(item) ? item : [
12049
+ item
12050
+ ],
12051
+ shareScope: options.shareScope || "default"
12052
+ }), (item)=>({
12053
+ external: Array.isArray(item.external) ? item.external : [
12054
+ item.external
12055
+ ],
12056
+ shareScope: item.shareScope || options.shareScope || "default"
12057
+ })), remoteInfos = {};
12058
+ for (let [key, config] of remotes)for (let external of config.external){
12059
+ let [externalType, externalRequest] = function(external) {
12060
+ let result = function(external) {
12061
+ if (/^[a-z0-9-]+ /.test(external)) {
12062
+ let idx = external.indexOf(" ");
12063
+ return [
12064
+ external.slice(0, idx),
12065
+ external.slice(idx + 1)
12066
+ ];
12067
+ }
12068
+ return null;
12069
+ }(external);
12070
+ return null === result ? [
12071
+ remoteType,
12072
+ external
12073
+ ] : result;
12074
+ }(external);
12075
+ if (remoteInfos[key] ??= [], "script" === externalType) {
12076
+ let [url, global] = function(urlAndGlobal) {
12077
+ let index = urlAndGlobal.indexOf("@");
12078
+ return index <= 0 || index === urlAndGlobal.length - 1 ? null : [
12079
+ urlAndGlobal.substring(index + 1),
12080
+ urlAndGlobal.substring(0, index)
12081
+ ];
12082
+ }(externalRequest);
12083
+ remoteInfos[key].push({
12084
+ alias: key,
12085
+ name: global,
12086
+ entry: url,
12087
+ externalType,
12088
+ shareScope: config.shareScope
12089
+ });
12090
+ } else remoteInfos[key].push({
12091
+ alias: key,
12092
+ name: void 0,
12093
+ entry: void 0,
12094
+ externalType,
12095
+ shareScope: config.shareScope
12096
+ });
12097
+ }
12098
+ return remoteInfos;
11715
12099
  }
11716
12100
  class ContainerPlugin extends RspackBuiltinPlugin {
11717
12101
  name = binding_.BuiltinPluginName.ContainerPlugin;
@@ -11804,7 +12188,7 @@ Help:
11804
12188
  let _options = JSON.stringify(options || {});
11805
12189
  return binding_default().transform(source, _options);
11806
12190
  }
11807
- let exports_rspackVersion = "1.6.5-canary-480f74ac-20251120174032", exports_version = "5.75.0", exports_WebpackError = Error, sources = __webpack_require__("webpack-sources"), exports_config = {
12191
+ let exports_rspackVersion = "1.6.5-canary-1b7f543c-20251121112112", exports_version = "5.75.0", exports_WebpackError = Error, sources = __webpack_require__("webpack-sources"), exports_config = {
11808
12192
  getNormalizedRspackOptions: getNormalizedRspackOptions,
11809
12193
  applyRspackOptionsDefaults: applyRspackOptionsDefaults,
11810
12194
  getNormalizedWebpackOptions: getNormalizedRspackOptions,
@@ -11847,12 +12231,13 @@ Help:
11847
12231
  ContainerReferencePlugin: ContainerReferencePlugin,
11848
12232
  ModuleFederationPlugin: class {
11849
12233
  _options;
12234
+ _independentSharePlugin;
11850
12235
  constructor(_options){
11851
12236
  this._options = _options;
11852
12237
  }
11853
12238
  apply(compiler) {
11854
- var options;
11855
- let runtimeToolsPath, bundlerRuntimePath, runtimePath, { webpack } = compiler, paths = (runtimeToolsPath = (options = this._options).implementation ?? require.resolve("@module-federation/runtime-tools"), bundlerRuntimePath = require.resolve("@module-federation/webpack-bundler-runtime", {
12239
+ var options, options1;
12240
+ let runtimeToolsPath, bundlerRuntimePath, runtimePath, { name, shared } = this._options, { webpack } = compiler, paths = (runtimeToolsPath = (options = this._options).implementation ?? require.resolve("@module-federation/runtime-tools"), bundlerRuntimePath = require.resolve("@module-federation/webpack-bundler-runtime", {
11856
12241
  paths: [
11857
12242
  runtimeToolsPath
11858
12243
  ]
@@ -11865,101 +12250,54 @@ Help:
11865
12250
  bundlerRuntime: bundlerRuntimePath,
11866
12251
  runtime: runtimePath
11867
12252
  });
11868
- if (compiler.options.resolve.alias = {
12253
+ compiler.options.resolve.alias = {
11869
12254
  "@module-federation/runtime-tools": paths.runtimeTools,
11870
12255
  "@module-federation/runtime": paths.runtime,
11871
12256
  ...compiler.options.resolve.alias
11872
- }, new ModuleFederationRuntimePlugin({
11873
- entryRuntime: function(paths, options, compiler) {
11874
- let runtimePlugins = options.runtimePlugins ?? [], remoteInfos = getRemoteInfos(options), runtimePluginImports = [], runtimePluginVars = [];
11875
- for(let i = 0; i < runtimePlugins.length; i++){
11876
- let runtimePluginVar = `__module_federation_runtime_plugin_${i}__`, pluginSpec = runtimePlugins[i], pluginPath = Array.isArray(pluginSpec) ? pluginSpec[0] : pluginSpec, pluginParams = Array.isArray(pluginSpec) ? pluginSpec[1] : void 0;
11877
- runtimePluginImports.push(`import ${runtimePluginVar} from ${JSON.stringify(pluginPath)}`);
11878
- let paramsCode = void 0 === pluginParams ? "undefined" : JSON.stringify(pluginParams);
11879
- runtimePluginVars.push(`${runtimePluginVar}(${paramsCode})`);
11880
- }
11881
- let content = [
11882
- `import __module_federation_bundler_runtime__ from ${JSON.stringify(paths.bundlerRuntime)}`,
11883
- ...runtimePluginImports,
11884
- `const __module_federation_runtime_plugins__ = [${runtimePluginVars.join(", ")}]`,
11885
- `const __module_federation_remote_infos__ = ${JSON.stringify(remoteInfos)}`,
11886
- `const __module_federation_container_name__ = ${JSON.stringify(options.name ?? compiler.options.output.uniqueName)}`,
11887
- `const __module_federation_share_strategy__ = ${JSON.stringify(options.shareStrategy ?? "version-first")}`,
11888
- compiler.webpack.Template.getFunctionContent(__webpack_require__("./moduleFederationDefaultRuntime.js"))
11889
- ].join(";");
11890
- return `@module-federation/runtime/rspack.js!=!data:text/javascript,${content}`;
11891
- }(paths, this._options, compiler)
11892
- }).apply(compiler), new webpack.container.ModuleFederationPluginV1({
12257
+ }, ((options1 = this._options).shared ? parseOptions(options1.shared, (item, key)=>{
12258
+ if ("string" != typeof item) throw Error("Unexpected array in shared");
12259
+ return item !== key && isRequiredVersion(item) ? {
12260
+ import: key,
12261
+ requiredVersion: item
12262
+ } : {
12263
+ import: item
12264
+ };
12265
+ }, (item)=>item) : []).filter(([, config])=>config.treeshake).length > 0 && (this._independentSharePlugin = new IndependentSharePlugin({
12266
+ name,
12267
+ shared: shared || {},
12268
+ outputFilePath: this._options.independentShareFilePath
12269
+ }), this._independentSharePlugin.apply(compiler));
12270
+ let runtimePluginApplied = !1;
12271
+ compiler.hooks.beforeRun.tapPromise({
12272
+ name: "ModuleFederationPlugin",
12273
+ stage: 100
12274
+ }, async ()=>{
12275
+ runtimePluginApplied || (runtimePluginApplied = !0, new ModuleFederationRuntimePlugin({
12276
+ entryRuntime: function(paths, options, compiler, treeshakeShareFallbacks) {
12277
+ let runtimePlugins = options.runtimePlugins ?? [], remoteInfos = getRemoteInfos(options), runtimePluginImports = [], runtimePluginVars = [];
12278
+ for(let i = 0; i < runtimePlugins.length; i++){
12279
+ let runtimePluginVar = `__module_federation_runtime_plugin_${i}__`, pluginSpec = runtimePlugins[i], pluginPath = Array.isArray(pluginSpec) ? pluginSpec[0] : pluginSpec, pluginParams = Array.isArray(pluginSpec) ? pluginSpec[1] : void 0;
12280
+ runtimePluginImports.push(`import ${runtimePluginVar} from ${JSON.stringify(pluginPath)}`);
12281
+ let paramsCode = void 0 === pluginParams ? "undefined" : JSON.stringify(pluginParams);
12282
+ runtimePluginVars.push(`${runtimePluginVar}(${paramsCode})`);
12283
+ }
12284
+ let content = [
12285
+ `import __module_federation_bundler_runtime__ from ${JSON.stringify(paths.bundlerRuntime)}`,
12286
+ ...runtimePluginImports,
12287
+ `const __module_federation_runtime_plugins__ = [${runtimePluginVars.join(", ")}]`,
12288
+ `const __module_federation_remote_infos__ = ${JSON.stringify(remoteInfos)}`,
12289
+ `const __module_federation_container_name__ = ${JSON.stringify(options.name ?? compiler.options.output.uniqueName)}`,
12290
+ `const __module_federation_share_strategy__ = ${JSON.stringify(options.shareStrategy ?? "version-first")}`,
12291
+ `const __module_federation_share_fallbacks__ = ${JSON.stringify(treeshakeShareFallbacks)}`,
12292
+ compiler.webpack.Template.getFunctionContent(__webpack_require__("./moduleFederationDefaultRuntime.js"))
12293
+ ].join(";");
12294
+ return `@module-federation/runtime/rspack.js!=!data:text/javascript,${content}`;
12295
+ }(paths, this._options, compiler, this._independentSharePlugin?.buildAssets || {})
12296
+ }).apply(compiler));
12297
+ }), new webpack.container.ModuleFederationPluginV1({
11893
12298
  ...this._options,
11894
12299
  enhanced: !0
11895
- }).apply(compiler), this._options.manifest) {
11896
- let manifestOptions = !0 === this._options.manifest ? {} : {
11897
- ...this._options.manifest
11898
- }, containerName = manifestOptions.name ?? this._options.name, globalName = manifestOptions.globalName ?? function(library) {
11899
- if (!library) return;
11900
- let libName = library.name;
11901
- if (libName) {
11902
- if ("string" == typeof libName) return libName;
11903
- if (Array.isArray(libName)) return libName[0];
11904
- if ("object" == typeof libName) return libName.root?.[0] ?? libName.amd ?? libName.commonjs ?? void 0;
11905
- }
11906
- }(this._options.library) ?? containerName, remoteAliasMap = Object.entries(getRemoteInfos(this._options)).reduce((sum, cur)=>{
11907
- if (cur[1].length > 1) return sum;
11908
- let { entry, alias, name } = cur[1][0];
11909
- return entry && name && (sum[alias] = {
11910
- name,
11911
- entry
11912
- }), sum;
11913
- }, {}), manifestExposes = function(exposes) {
11914
- if (!exposes) return;
11915
- let result = parseOptions(exposes, (value, key)=>({
11916
- import: Array.isArray(value) ? value : [
11917
- value
11918
- ],
11919
- name: void 0
11920
- }), (value)=>({
11921
- import: Array.isArray(value.import) ? value.import : [
11922
- value.import
11923
- ],
11924
- name: value.name ?? void 0
11925
- })).map(([exposeKey, info])=>{
11926
- let exposeName = info.name ?? exposeKey.replace(/^\.\//, "");
11927
- return {
11928
- path: exposeKey,
11929
- name: exposeName
11930
- };
11931
- });
11932
- return result.length > 0 ? result : void 0;
11933
- }(this._options.exposes);
11934
- void 0 === manifestOptions.exposes && manifestExposes && (manifestOptions.exposes = manifestExposes);
11935
- let manifestShared = function(shared) {
11936
- if (!shared) return;
11937
- let result = parseOptions(shared, (item, key)=>{
11938
- if ("string" != typeof item) throw Error("Unexpected array in shared");
11939
- return item !== key && isRequiredVersion(item) ? {
11940
- import: key,
11941
- requiredVersion: item
11942
- } : {
11943
- import: item
11944
- };
11945
- }, (item)=>item).map(([key, config])=>{
11946
- let name = config.shareKey || key, version = "string" == typeof config.version ? config.version : void 0;
11947
- return {
11948
- name,
11949
- version,
11950
- requiredVersion: "string" == typeof config.requiredVersion ? config.requiredVersion : void 0,
11951
- singleton: config.singleton
11952
- };
11953
- });
11954
- return result.length > 0 ? result : void 0;
11955
- }(this._options.shared);
11956
- void 0 === manifestOptions.shared && manifestShared && (manifestOptions.shared = manifestShared), new ModuleFederationManifestPlugin({
11957
- ...manifestOptions,
11958
- name: containerName,
11959
- globalName,
11960
- remoteAliasMap
11961
- }).apply(compiler);
11962
- }
12300
+ }).apply(compiler), this._options.manifest && new ModuleFederationManifestPlugin(this._options).apply(compiler);
11963
12301
  }
11964
12302
  },
11965
12303
  ModuleFederationPluginV1: class {
@@ -11996,6 +12334,33 @@ Help:
11996
12334
  }
11997
12335
  }, sharing = {
11998
12336
  ProvideSharedPlugin: ProvideSharedPlugin,
12337
+ CollectShareEntryPlugin: CollectShareEntryPlugin,
12338
+ TreeshakeSharePlugin: class {
12339
+ mfConfig;
12340
+ outputDir;
12341
+ plugins;
12342
+ reshake;
12343
+ name = "TreeshakeSharePlugin";
12344
+ constructor(options){
12345
+ const { mfConfig, plugins, reshake } = options;
12346
+ this.mfConfig = mfConfig, this.outputDir = mfConfig.independentShareDir || "independent-packages", this.plugins = plugins, this.reshake = !!reshake;
12347
+ }
12348
+ apply(compiler) {
12349
+ let { mfConfig, outputDir, plugins, reshake } = this, { name, shared, library } = mfConfig;
12350
+ if (!shared) return;
12351
+ let sharedOptions = normalizeSharedOptions(shared);
12352
+ sharedOptions.length && (reshake || new OptimizeDependencyReferencedExportsPlugin(sharedOptions, mfConfig.injectUsedExports, mfConfig.manifest).apply(compiler), sharedOptions.some(([_, config])=>config.treeshake && !1 !== config.import) && new IndependentSharePlugin({
12353
+ name: name,
12354
+ shared: shared,
12355
+ outputDir,
12356
+ plugins,
12357
+ treeshake: reshake,
12358
+ library
12359
+ }).apply(compiler));
12360
+ }
12361
+ },
12362
+ ShareContainerPlugin: ShareContainerPlugin,
12363
+ OptimizeDependencyReferencedExportsPlugin: OptimizeDependencyReferencedExportsPlugin,
11999
12364
  ConsumeSharedPlugin: ConsumeSharedPlugin,
12000
12365
  SharePlugin: SharePlugin
12001
12366
  }, exports_experiments = {