@rspack-canary/core 1.6.7-canary-ceb43c53-20251208173610 → 1.6.7-canary-f7e6adf4-20251211131042
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/container/ModuleFederationManifestPlugin.d.ts +9 -2
- package/dist/container/ModuleFederationPlugin.d.ts +16 -1
- package/dist/exports.d.ts +3 -0
- package/dist/index.js +623 -245
- package/dist/moduleFederationDefaultRuntime.js +1 -1
- package/dist/sharing/CollectSharedEntryPlugin.d.ts +22 -0
- package/dist/sharing/ConsumeSharedPlugin.d.ts +16 -0
- package/dist/sharing/IndependentSharedPlugin.d.ts +35 -0
- package/dist/sharing/ProvideSharedPlugin.d.ts +19 -0
- package/dist/sharing/SharePlugin.d.ts +36 -0
- package/dist/sharing/SharedContainerPlugin.d.ts +23 -0
- package/dist/sharing/SharedUsedExportsOptimizerPlugin.d.ts +14 -0
- package/dist/sharing/TreeShakeSharedPlugin.d.ts +19 -0
- package/dist/sharing/utils.d.ts +1 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -5785,7 +5785,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|
|
5785
5785
|
}, applyExperimentsDefaults = (experiments, { development })=>{
|
|
5786
5786
|
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);
|
|
5787
5787
|
}, applybundlerInfoDefaults = (rspackFuture, library)=>{
|
|
5788
|
-
"object" == typeof rspackFuture && (D(rspackFuture, "bundlerInfo", {}), "object" == typeof rspackFuture.bundlerInfo && (D(rspackFuture.bundlerInfo, "version", "1.6.7-canary-
|
|
5788
|
+
"object" == typeof rspackFuture && (D(rspackFuture, "bundlerInfo", {}), "object" == typeof rspackFuture.bundlerInfo && (D(rspackFuture.bundlerInfo, "version", "1.6.7-canary-f7e6adf4-20251211131042"), D(rspackFuture.bundlerInfo, "bundler", "rspack"), D(rspackFuture.bundlerInfo, "force", !library)));
|
|
5789
5789
|
}, applySnapshotDefaults = (_snapshot, _env)=>{}, applyModuleDefaults = (module1, { cache, asyncWebAssembly, css, targetProperties, mode, uniqueName, usedExports, inlineConst, deferImport })=>{
|
|
5790
5790
|
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 })=>{
|
|
5791
5791
|
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", [
|
|
@@ -7545,7 +7545,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|
|
7545
7545
|
});
|
|
7546
7546
|
}
|
|
7547
7547
|
}
|
|
7548
|
-
let CORE_VERSION = "1.6.7-canary-
|
|
7548
|
+
let CORE_VERSION = "1.6.7-canary-f7e6adf4-20251211131042", bindingVersionCheck_errorMessage = (coreVersion, expectedCoreVersion)=>process.env.RSPACK_BINDING ? `Unmatched version @rspack/core@${coreVersion} and binding version.
|
|
7549
7549
|
|
|
7550
7550
|
Help:
|
|
7551
7551
|
Looks like you are using a custom binding (via environment variable 'RSPACK_BINDING=${process.env.RSPACK_BINDING}').
|
|
@@ -8854,7 +8854,7 @@ Help:
|
|
|
8854
8854
|
obj.children = this.stats.map((stat, idx)=>{
|
|
8855
8855
|
let obj = stat.toJson(childOptions.children[idx]), compilationName = stat.compilation.name;
|
|
8856
8856
|
return obj.name = compilationName && makePathsRelative(childOptions.context, compilationName, stat.compilation.compiler.root), obj;
|
|
8857
|
-
}), childOptions.version && (obj.rspackVersion = "1.6.7-canary-
|
|
8857
|
+
}), childOptions.version && (obj.rspackVersion = "1.6.7-canary-f7e6adf4-20251211131042", obj.version = "5.75.0"), childOptions.hash && (obj.hash = obj.children.map((j)=>j.hash).join(""));
|
|
8858
8858
|
let mapError = (j, obj)=>({
|
|
8859
8859
|
...obj,
|
|
8860
8860
|
compilerPath: obj.compilerPath ? `${j.name}.${obj.compilerPath}` : j.name
|
|
@@ -9753,7 +9753,7 @@ Help:
|
|
|
9753
9753
|
object.hash = context.getStatsCompilation(compilation).hash;
|
|
9754
9754
|
},
|
|
9755
9755
|
version: (object)=>{
|
|
9756
|
-
object.version = "5.75.0", object.rspackVersion = "1.6.7-canary-
|
|
9756
|
+
object.version = "5.75.0", object.rspackVersion = "1.6.7-canary-f7e6adf4-20251211131042";
|
|
9757
9757
|
},
|
|
9758
9758
|
env: (object, _compilation, _context, { _env })=>{
|
|
9759
9759
|
object.env = _env;
|
|
@@ -11598,30 +11598,120 @@ Help:
|
|
|
11598
11598
|
function isRequiredVersion(str) {
|
|
11599
11599
|
return VERSION_PATTERN_REGEXP.test(str);
|
|
11600
11600
|
}
|
|
11601
|
-
let
|
|
11601
|
+
let encodeName = function(name, prefix = "", withExt = !1) {
|
|
11602
|
+
return `${prefix}${name.replace(/@/g, "scope_").replace(/-/g, "_").replace(/\//g, "__").replace(/\./g, "")}${withExt ? ".js" : ""}`;
|
|
11603
|
+
}, parseOptions = (options, normalizeSimple, normalizeOptions)=>{
|
|
11604
|
+
let items = [];
|
|
11605
|
+
var options1 = options, normalizeSimple1 = normalizeSimple, normalizeOptions1 = normalizeOptions, fn = (key, value)=>{
|
|
11606
|
+
items.push([
|
|
11607
|
+
key,
|
|
11608
|
+
value
|
|
11609
|
+
]);
|
|
11610
|
+
};
|
|
11611
|
+
let object = (obj)=>{
|
|
11612
|
+
for (let [key, value] of Object.entries(obj))"string" == typeof value || Array.isArray(value) ? fn(key, normalizeSimple1(value, key)) : fn(key, normalizeOptions1(value, key));
|
|
11613
|
+
};
|
|
11614
|
+
if (options1) if (Array.isArray(options1)) {
|
|
11615
|
+
var items1 = options1;
|
|
11616
|
+
for (let item of items1)if ("string" == typeof item) fn(item, normalizeSimple1(item, item));
|
|
11617
|
+
else if (item && "object" == typeof item) object(item);
|
|
11618
|
+
else throw Error("Unexpected options format");
|
|
11619
|
+
} else if ("object" == typeof options1) object(options1);
|
|
11620
|
+
else throw Error("Unexpected options format");
|
|
11621
|
+
return items;
|
|
11622
|
+
}, MANIFEST_FILE_NAME = "mf-manifest.json", STATS_FILE_NAME = "mf-stats.json", JSON_EXT = ".json";
|
|
11602
11623
|
function isPlainObject(value) {
|
|
11603
11624
|
return !!value && "object" == typeof value && !Array.isArray(value);
|
|
11604
11625
|
}
|
|
11626
|
+
function getFileName(manifestOptions) {
|
|
11627
|
+
var name;
|
|
11628
|
+
if (!manifestOptions) return {
|
|
11629
|
+
statsFileName: "",
|
|
11630
|
+
manifestFileName: ""
|
|
11631
|
+
};
|
|
11632
|
+
if ("boolean" == typeof manifestOptions) return {
|
|
11633
|
+
statsFileName: STATS_FILE_NAME,
|
|
11634
|
+
manifestFileName: MANIFEST_FILE_NAME
|
|
11635
|
+
};
|
|
11636
|
+
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;
|
|
11637
|
+
return {
|
|
11638
|
+
statsFileName: (0, external_node_path_namespaceObject.join)(filePath, statsFileName),
|
|
11639
|
+
manifestFileName: (0, external_node_path_namespaceObject.join)(filePath, manifestFileName)
|
|
11640
|
+
};
|
|
11641
|
+
}
|
|
11605
11642
|
class ModuleFederationManifestPlugin extends RspackBuiltinPlugin {
|
|
11606
11643
|
name = binding_.BuiltinPluginName.ModuleFederationManifestPlugin;
|
|
11607
11644
|
opts;
|
|
11608
11645
|
constructor(opts){
|
|
11609
|
-
|
|
11646
|
+
var mfConfig;
|
|
11647
|
+
let manifestOptions, containerName, globalName, remoteAliasMap, manifestExposes, manifestShared;
|
|
11648
|
+
super(), this.opts = (manifestOptions = !0 === (mfConfig = opts).manifest ? {} : {
|
|
11649
|
+
...mfConfig.manifest
|
|
11650
|
+
}, containerName = mfConfig.name, globalName = function(library) {
|
|
11651
|
+
if (!library) return;
|
|
11652
|
+
let libName = library.name;
|
|
11653
|
+
if (libName) {
|
|
11654
|
+
if ("string" == typeof libName) return libName;
|
|
11655
|
+
if (Array.isArray(libName)) return libName[0];
|
|
11656
|
+
if ("object" == typeof libName) return libName.root?.[0] ?? libName.amd ?? libName.commonjs ?? void 0;
|
|
11657
|
+
}
|
|
11658
|
+
}(mfConfig.library) ?? containerName, remoteAliasMap = Object.entries(getRemoteInfos(mfConfig)).reduce((sum, cur)=>{
|
|
11659
|
+
if (cur[1].length > 1) return sum;
|
|
11660
|
+
let { entry, alias, name } = cur[1][0];
|
|
11661
|
+
return entry && name && (sum[alias] = {
|
|
11662
|
+
name,
|
|
11663
|
+
entry
|
|
11664
|
+
}), sum;
|
|
11665
|
+
}, {}), manifestExposes = function(exposes) {
|
|
11666
|
+
if (!exposes) return;
|
|
11667
|
+
let result = parseOptions(exposes, (value)=>({
|
|
11668
|
+
import: Array.isArray(value) ? value : [
|
|
11669
|
+
value
|
|
11670
|
+
],
|
|
11671
|
+
name: void 0
|
|
11672
|
+
}), (value)=>({
|
|
11673
|
+
import: Array.isArray(value.import) ? value.import : [
|
|
11674
|
+
value.import
|
|
11675
|
+
],
|
|
11676
|
+
name: value.name ?? void 0
|
|
11677
|
+
})).map(([exposeKey, info])=>{
|
|
11678
|
+
let exposeName = info.name ?? exposeKey.replace(/^\.\//, "");
|
|
11679
|
+
return {
|
|
11680
|
+
path: exposeKey,
|
|
11681
|
+
name: exposeName
|
|
11682
|
+
};
|
|
11683
|
+
});
|
|
11684
|
+
return result.length > 0 ? result : void 0;
|
|
11685
|
+
}(mfConfig.exposes), void 0 === manifestOptions.exposes && manifestExposes && (manifestOptions.exposes = manifestExposes), manifestShared = function(shared) {
|
|
11686
|
+
if (!shared) return;
|
|
11687
|
+
let result = parseOptions(shared, (item, key)=>{
|
|
11688
|
+
if ("string" != typeof item) throw Error("Unexpected array in shared");
|
|
11689
|
+
return item !== key && isRequiredVersion(item) ? {
|
|
11690
|
+
import: key,
|
|
11691
|
+
requiredVersion: item
|
|
11692
|
+
} : {
|
|
11693
|
+
import: item
|
|
11694
|
+
};
|
|
11695
|
+
}, (item)=>item).map(([key, config])=>{
|
|
11696
|
+
let name = config.shareKey || key, version = "string" == typeof config.version ? config.version : void 0;
|
|
11697
|
+
return {
|
|
11698
|
+
name,
|
|
11699
|
+
version,
|
|
11700
|
+
requiredVersion: "string" == typeof config.requiredVersion ? config.requiredVersion : void 0,
|
|
11701
|
+
singleton: config.singleton
|
|
11702
|
+
};
|
|
11703
|
+
});
|
|
11704
|
+
return result.length > 0 ? result : void 0;
|
|
11705
|
+
}(mfConfig.shared), void 0 === manifestOptions.shared && manifestShared && (manifestOptions.shared = manifestShared), {
|
|
11706
|
+
...manifestOptions,
|
|
11707
|
+
remoteAliasMap,
|
|
11708
|
+
globalName,
|
|
11709
|
+
name: containerName
|
|
11710
|
+
});
|
|
11610
11711
|
}
|
|
11611
11712
|
raw(compiler) {
|
|
11612
11713
|
var isDev;
|
|
11613
|
-
let pkg, buildVersion, { fileName, filePath, disableAssetsAnalyze, remoteAliasMap, exposes, shared } = this.opts, { statsFileName, manifestFileName } =
|
|
11614
|
-
var name;
|
|
11615
|
-
if (!manifestOptions) return {
|
|
11616
|
-
statsFileName: STATS_FILE_NAME,
|
|
11617
|
-
manifestFileName: MANIFEST_FILE_NAME
|
|
11618
|
-
};
|
|
11619
|
-
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;
|
|
11620
|
-
return {
|
|
11621
|
-
statsFileName: (0, external_node_path_namespaceObject.join)(filePath, statsFileName),
|
|
11622
|
-
manifestFileName: (0, external_node_path_namespaceObject.join)(filePath, manifestFileName)
|
|
11623
|
-
};
|
|
11624
|
-
}(this.opts), rawOptions = {
|
|
11714
|
+
let pkg, buildVersion, { fileName, filePath, disableAssetsAnalyze, remoteAliasMap, exposes, shared } = this.opts, { statsFileName, manifestFileName } = getFileName(this.opts), rawOptions = {
|
|
11625
11715
|
name: this.opts.name,
|
|
11626
11716
|
globalName: this.opts.globalName,
|
|
11627
11717
|
fileName,
|
|
@@ -11656,81 +11746,6 @@ Help:
|
|
|
11656
11746
|
return createBuiltinPlugin(this.name, rawOptions);
|
|
11657
11747
|
}
|
|
11658
11748
|
}
|
|
11659
|
-
let ModuleFederationRuntimePlugin = base_create(binding_.BuiltinPluginName.ModuleFederationRuntimePlugin, (options = {})=>options), parseOptions = (options, normalizeSimple, normalizeOptions)=>{
|
|
11660
|
-
let items = [];
|
|
11661
|
-
var options1 = options, normalizeSimple1 = normalizeSimple, normalizeOptions1 = normalizeOptions, fn = (key, value)=>{
|
|
11662
|
-
items.push([
|
|
11663
|
-
key,
|
|
11664
|
-
value
|
|
11665
|
-
]);
|
|
11666
|
-
};
|
|
11667
|
-
let object = (obj)=>{
|
|
11668
|
-
for (let [key, value] of Object.entries(obj))"string" == typeof value || Array.isArray(value) ? fn(key, normalizeSimple1(value, key)) : fn(key, normalizeOptions1(value, key));
|
|
11669
|
-
};
|
|
11670
|
-
if (options1) if (Array.isArray(options1)) {
|
|
11671
|
-
var items1 = options1;
|
|
11672
|
-
for (let item of items1)if ("string" == typeof item) fn(item, normalizeSimple1(item, item));
|
|
11673
|
-
else if (item && "object" == typeof item) object(item);
|
|
11674
|
-
else throw Error("Unexpected options format");
|
|
11675
|
-
} else if ("object" == typeof options1) object(options1);
|
|
11676
|
-
else throw Error("Unexpected options format");
|
|
11677
|
-
return items;
|
|
11678
|
-
};
|
|
11679
|
-
function getRemoteInfos(options) {
|
|
11680
|
-
if (!options.remotes) return {};
|
|
11681
|
-
let remoteType = options.remoteType || (options.library ? options.library.type : "script"), remotes = parseOptions(options.remotes, (item)=>({
|
|
11682
|
-
external: Array.isArray(item) ? item : [
|
|
11683
|
-
item
|
|
11684
|
-
],
|
|
11685
|
-
shareScope: options.shareScope || "default"
|
|
11686
|
-
}), (item)=>({
|
|
11687
|
-
external: Array.isArray(item.external) ? item.external : [
|
|
11688
|
-
item.external
|
|
11689
|
-
],
|
|
11690
|
-
shareScope: item.shareScope || options.shareScope || "default"
|
|
11691
|
-
})), remoteInfos = {};
|
|
11692
|
-
for (let [key, config] of remotes)for (let external of config.external){
|
|
11693
|
-
let [externalType, externalRequest] = function(external) {
|
|
11694
|
-
let result = function(external) {
|
|
11695
|
-
if (/^[a-z0-9-]+ /.test(external)) {
|
|
11696
|
-
let idx = external.indexOf(" ");
|
|
11697
|
-
return [
|
|
11698
|
-
external.slice(0, idx),
|
|
11699
|
-
external.slice(idx + 1)
|
|
11700
|
-
];
|
|
11701
|
-
}
|
|
11702
|
-
return null;
|
|
11703
|
-
}(external);
|
|
11704
|
-
return null === result ? [
|
|
11705
|
-
remoteType,
|
|
11706
|
-
external
|
|
11707
|
-
] : result;
|
|
11708
|
-
}(external);
|
|
11709
|
-
if (remoteInfos[key] ??= [], "script" === externalType) {
|
|
11710
|
-
let [url, global] = function(urlAndGlobal) {
|
|
11711
|
-
let index = urlAndGlobal.indexOf("@");
|
|
11712
|
-
return index <= 0 || index === urlAndGlobal.length - 1 ? null : [
|
|
11713
|
-
urlAndGlobal.substring(index + 1),
|
|
11714
|
-
urlAndGlobal.substring(0, index)
|
|
11715
|
-
];
|
|
11716
|
-
}(externalRequest);
|
|
11717
|
-
remoteInfos[key].push({
|
|
11718
|
-
alias: key,
|
|
11719
|
-
name: global,
|
|
11720
|
-
entry: url,
|
|
11721
|
-
externalType,
|
|
11722
|
-
shareScope: config.shareScope
|
|
11723
|
-
});
|
|
11724
|
-
} else remoteInfos[key].push({
|
|
11725
|
-
alias: key,
|
|
11726
|
-
name: void 0,
|
|
11727
|
-
entry: void 0,
|
|
11728
|
-
externalType,
|
|
11729
|
-
shareScope: config.shareScope
|
|
11730
|
-
});
|
|
11731
|
-
}
|
|
11732
|
-
return remoteInfos;
|
|
11733
|
-
}
|
|
11734
11749
|
let compilerSet = new WeakSet();
|
|
11735
11750
|
class ShareRuntimePlugin extends RspackBuiltinPlugin {
|
|
11736
11751
|
enhanced;
|
|
@@ -11743,42 +11758,48 @@ Help:
|
|
|
11743
11758
|
if (compiler1 = compiler, !compilerSet.has(compiler1)) return compiler2 = compiler, compilerSet.add(compiler2), createBuiltinPlugin(this.name, this.enhanced);
|
|
11744
11759
|
}
|
|
11745
11760
|
}
|
|
11761
|
+
function normalizeConsumeShareOptions(consumes, shareScope) {
|
|
11762
|
+
return parseOptions(consumes, (item, key)=>{
|
|
11763
|
+
if (Array.isArray(item)) throw Error("Unexpected array in options");
|
|
11764
|
+
return item !== key && isRequiredVersion(item) ? {
|
|
11765
|
+
import: key,
|
|
11766
|
+
shareScope: shareScope || "default",
|
|
11767
|
+
shareKey: key,
|
|
11768
|
+
requiredVersion: item,
|
|
11769
|
+
strictVersion: !0,
|
|
11770
|
+
packageName: void 0,
|
|
11771
|
+
singleton: !1,
|
|
11772
|
+
eager: !1,
|
|
11773
|
+
treeshakeStrategy: void 0
|
|
11774
|
+
} : {
|
|
11775
|
+
import: key,
|
|
11776
|
+
shareScope: shareScope || "default",
|
|
11777
|
+
shareKey: key,
|
|
11778
|
+
requiredVersion: void 0,
|
|
11779
|
+
packageName: void 0,
|
|
11780
|
+
strictVersion: !1,
|
|
11781
|
+
singleton: !1,
|
|
11782
|
+
eager: !1,
|
|
11783
|
+
treeshakeStrategy: void 0
|
|
11784
|
+
};
|
|
11785
|
+
}, (item, key)=>({
|
|
11786
|
+
import: !1 === item.import ? void 0 : item.import || key,
|
|
11787
|
+
shareScope: item.shareScope || shareScope || "default",
|
|
11788
|
+
shareKey: item.shareKey || key,
|
|
11789
|
+
requiredVersion: item.requiredVersion,
|
|
11790
|
+
strictVersion: "boolean" == typeof item.strictVersion ? item.strictVersion : !1 !== item.import && !item.singleton,
|
|
11791
|
+
packageName: item.packageName,
|
|
11792
|
+
singleton: !!item.singleton,
|
|
11793
|
+
eager: !!item.eager,
|
|
11794
|
+
treeshakeStrategy: item.treeshakeStrategy
|
|
11795
|
+
}));
|
|
11796
|
+
}
|
|
11746
11797
|
class ConsumeSharedPlugin extends RspackBuiltinPlugin {
|
|
11747
11798
|
name = binding_.BuiltinPluginName.ConsumeSharedPlugin;
|
|
11748
11799
|
_options;
|
|
11749
11800
|
constructor(options){
|
|
11750
11801
|
super(), this._options = {
|
|
11751
|
-
consumes:
|
|
11752
|
-
if (Array.isArray(item)) throw Error("Unexpected array in options");
|
|
11753
|
-
return item !== key && isRequiredVersion(item) ? {
|
|
11754
|
-
import: key,
|
|
11755
|
-
shareScope: options.shareScope || "default",
|
|
11756
|
-
shareKey: key,
|
|
11757
|
-
requiredVersion: item,
|
|
11758
|
-
strictVersion: !0,
|
|
11759
|
-
packageName: void 0,
|
|
11760
|
-
singleton: !1,
|
|
11761
|
-
eager: !1
|
|
11762
|
-
} : {
|
|
11763
|
-
import: key,
|
|
11764
|
-
shareScope: options.shareScope || "default",
|
|
11765
|
-
shareKey: key,
|
|
11766
|
-
requiredVersion: void 0,
|
|
11767
|
-
packageName: void 0,
|
|
11768
|
-
strictVersion: !1,
|
|
11769
|
-
singleton: !1,
|
|
11770
|
-
eager: !1
|
|
11771
|
-
};
|
|
11772
|
-
}, (item, key)=>({
|
|
11773
|
-
import: !1 === item.import ? void 0 : item.import || key,
|
|
11774
|
-
shareScope: item.shareScope || options.shareScope || "default",
|
|
11775
|
-
shareKey: item.shareKey || key,
|
|
11776
|
-
requiredVersion: item.requiredVersion,
|
|
11777
|
-
strictVersion: "boolean" == typeof item.strictVersion ? item.strictVersion : !1 !== item.import && !item.singleton,
|
|
11778
|
-
packageName: item.packageName,
|
|
11779
|
-
singleton: !!item.singleton,
|
|
11780
|
-
eager: !!item.eager
|
|
11781
|
-
})),
|
|
11802
|
+
consumes: normalizeConsumeShareOptions(options.consumes, options.shareScope),
|
|
11782
11803
|
enhanced: options.enhanced ?? !1
|
|
11783
11804
|
};
|
|
11784
11805
|
}
|
|
@@ -11799,28 +11820,30 @@ Help:
|
|
|
11799
11820
|
_provides;
|
|
11800
11821
|
_enhanced;
|
|
11801
11822
|
constructor(options){
|
|
11802
|
-
|
|
11823
|
+
var options1, shareScope, enhanced;
|
|
11824
|
+
super(), this._provides = (options1 = options.provides, shareScope = options.shareScope, enhanced = options.enhanced, parseOptions(options1, (item)=>{
|
|
11803
11825
|
if (Array.isArray(item)) throw Error("Unexpected array of provides");
|
|
11804
11826
|
return {
|
|
11805
11827
|
shareKey: item,
|
|
11806
11828
|
version: void 0,
|
|
11807
|
-
shareScope:
|
|
11829
|
+
shareScope: shareScope || "default",
|
|
11808
11830
|
eager: !1
|
|
11809
11831
|
};
|
|
11810
11832
|
}, (item)=>{
|
|
11811
11833
|
let raw = {
|
|
11812
11834
|
shareKey: item.shareKey,
|
|
11813
11835
|
version: item.version,
|
|
11814
|
-
shareScope: item.shareScope ||
|
|
11836
|
+
shareScope: item.shareScope || shareScope || "default",
|
|
11815
11837
|
eager: !!item.eager
|
|
11816
11838
|
};
|
|
11817
|
-
return
|
|
11839
|
+
return enhanced ? {
|
|
11818
11840
|
...raw,
|
|
11819
11841
|
singleton: item.singleton,
|
|
11820
11842
|
requiredVersion: item.requiredVersion,
|
|
11821
|
-
strictVersion: item.strictVersion
|
|
11843
|
+
strictVersion: item.strictVersion,
|
|
11844
|
+
treeshakeStrategy: item.treeshakeStrategy
|
|
11822
11845
|
} : raw;
|
|
11823
|
-
}), this._enhanced = options.enhanced;
|
|
11846
|
+
})), this._enhanced = options.enhanced;
|
|
11824
11847
|
}
|
|
11825
11848
|
raw(compiler) {
|
|
11826
11849
|
new ShareRuntimePlugin(this._enhanced ?? !1).apply(compiler);
|
|
@@ -11831,32 +11854,40 @@ Help:
|
|
|
11831
11854
|
return createBuiltinPlugin(this.name, rawOptions);
|
|
11832
11855
|
}
|
|
11833
11856
|
}
|
|
11857
|
+
function normalizeSharedOptions(shared) {
|
|
11858
|
+
return parseOptions(shared, (item, key)=>{
|
|
11859
|
+
if ("string" != typeof item) throw Error("Unexpected array in shared");
|
|
11860
|
+
return item !== key && isRequiredVersion(item) ? {
|
|
11861
|
+
import: key,
|
|
11862
|
+
requiredVersion: item
|
|
11863
|
+
} : {
|
|
11864
|
+
import: item
|
|
11865
|
+
};
|
|
11866
|
+
}, (item)=>item);
|
|
11867
|
+
}
|
|
11868
|
+
function createConsumeShareOptions(normalizedSharedOptions) {
|
|
11869
|
+
return normalizedSharedOptions.map(([key, options])=>({
|
|
11870
|
+
[key]: {
|
|
11871
|
+
import: options.import,
|
|
11872
|
+
shareKey: options.shareKey || key,
|
|
11873
|
+
shareScope: options.shareScope,
|
|
11874
|
+
requiredVersion: options.requiredVersion,
|
|
11875
|
+
strictVersion: options.strictVersion,
|
|
11876
|
+
singleton: options.singleton,
|
|
11877
|
+
packageName: options.packageName,
|
|
11878
|
+
eager: options.eager,
|
|
11879
|
+
treeshakeStrategy: options.treeshake?.strategy
|
|
11880
|
+
}
|
|
11881
|
+
}));
|
|
11882
|
+
}
|
|
11834
11883
|
class SharePlugin {
|
|
11835
11884
|
_shareScope;
|
|
11836
11885
|
_consumes;
|
|
11837
11886
|
_provides;
|
|
11838
11887
|
_enhanced;
|
|
11888
|
+
_sharedOptions;
|
|
11839
11889
|
constructor(options){
|
|
11840
|
-
const sharedOptions =
|
|
11841
|
-
if ("string" != typeof item) throw Error("Unexpected array in shared");
|
|
11842
|
-
return item !== key && isRequiredVersion(item) ? {
|
|
11843
|
-
import: key,
|
|
11844
|
-
requiredVersion: item
|
|
11845
|
-
} : {
|
|
11846
|
-
import: item
|
|
11847
|
-
};
|
|
11848
|
-
}, (item)=>item), consumes = sharedOptions.map(([key, options])=>({
|
|
11849
|
-
[key]: {
|
|
11850
|
-
import: options.import,
|
|
11851
|
-
shareKey: options.shareKey || key,
|
|
11852
|
-
shareScope: options.shareScope,
|
|
11853
|
-
requiredVersion: options.requiredVersion,
|
|
11854
|
-
strictVersion: options.strictVersion,
|
|
11855
|
-
singleton: options.singleton,
|
|
11856
|
-
packageName: options.packageName,
|
|
11857
|
-
eager: options.eager
|
|
11858
|
-
}
|
|
11859
|
-
})), provides = sharedOptions.filter(([, options])=>!1 !== options.import).map(([key, options])=>({
|
|
11890
|
+
const sharedOptions = normalizeSharedOptions(options.shared), consumes = createConsumeShareOptions(sharedOptions), provides = sharedOptions.filter(([, options])=>!1 !== options.import).map(([key, options])=>({
|
|
11860
11891
|
[options.import || key]: {
|
|
11861
11892
|
shareKey: options.shareKey || key,
|
|
11862
11893
|
shareScope: options.shareScope,
|
|
@@ -11864,10 +11895,11 @@ Help:
|
|
|
11864
11895
|
eager: options.eager,
|
|
11865
11896
|
singleton: options.singleton,
|
|
11866
11897
|
requiredVersion: options.requiredVersion,
|
|
11867
|
-
strictVersion: options.strictVersion
|
|
11898
|
+
strictVersion: options.strictVersion,
|
|
11899
|
+
treeshakeStrategy: options.treeshake?.strategy
|
|
11868
11900
|
}
|
|
11869
11901
|
}));
|
|
11870
|
-
this._shareScope = options.shareScope, this._consumes = consumes, this._provides = provides, this._enhanced = options.enhanced ?? !1;
|
|
11902
|
+
this._shareScope = options.shareScope, this._consumes = consumes, this._provides = provides, this._enhanced = options.enhanced ?? !1, this._sharedOptions = sharedOptions;
|
|
11871
11903
|
}
|
|
11872
11904
|
apply(compiler) {
|
|
11873
11905
|
new ConsumeSharedPlugin({
|
|
@@ -11881,6 +11913,397 @@ Help:
|
|
|
11881
11913
|
}).apply(compiler);
|
|
11882
11914
|
}
|
|
11883
11915
|
}
|
|
11916
|
+
let SHARE_ENTRY_ASSET = "collect-shared-entries.json";
|
|
11917
|
+
class CollectSharedEntryPlugin extends RspackBuiltinPlugin {
|
|
11918
|
+
name = binding_.BuiltinPluginName.CollectSharedEntryPlugin;
|
|
11919
|
+
sharedOptions;
|
|
11920
|
+
_collectedEntries;
|
|
11921
|
+
constructor(options){
|
|
11922
|
+
super();
|
|
11923
|
+
const { sharedOptions } = options;
|
|
11924
|
+
this.sharedOptions = sharedOptions, this._collectedEntries = {};
|
|
11925
|
+
}
|
|
11926
|
+
getData() {
|
|
11927
|
+
return this._collectedEntries;
|
|
11928
|
+
}
|
|
11929
|
+
getFilename() {
|
|
11930
|
+
return SHARE_ENTRY_ASSET;
|
|
11931
|
+
}
|
|
11932
|
+
apply(compiler) {
|
|
11933
|
+
super.apply(compiler), compiler.hooks.thisCompilation.tap("Collect shared entry", (compilation)=>{
|
|
11934
|
+
compilation.hooks.processAssets.tapPromise({
|
|
11935
|
+
name: "CollectSharedEntry",
|
|
11936
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE
|
|
11937
|
+
}, async ()=>{
|
|
11938
|
+
compilation.getAssets().forEach((asset)=>{
|
|
11939
|
+
asset.name === SHARE_ENTRY_ASSET && (this._collectedEntries = JSON.parse(asset.source.source().toString())), compilation.deleteAsset(asset.name);
|
|
11940
|
+
});
|
|
11941
|
+
});
|
|
11942
|
+
});
|
|
11943
|
+
}
|
|
11944
|
+
raw() {
|
|
11945
|
+
let rawOptions = {
|
|
11946
|
+
consumes: normalizeConsumeShareOptions(createConsumeShareOptions(this.sharedOptions)).map(([key, v])=>({
|
|
11947
|
+
key,
|
|
11948
|
+
...v
|
|
11949
|
+
})),
|
|
11950
|
+
filename: this.getFilename()
|
|
11951
|
+
};
|
|
11952
|
+
return createBuiltinPlugin(this.name, rawOptions);
|
|
11953
|
+
}
|
|
11954
|
+
}
|
|
11955
|
+
function assert(condition, msg) {
|
|
11956
|
+
if (!condition) throw Error(msg);
|
|
11957
|
+
}
|
|
11958
|
+
class SharedContainerPlugin extends RspackBuiltinPlugin {
|
|
11959
|
+
name = binding_.BuiltinPluginName.SharedContainerPlugin;
|
|
11960
|
+
filename = "";
|
|
11961
|
+
_options;
|
|
11962
|
+
_shareName;
|
|
11963
|
+
_globalName;
|
|
11964
|
+
constructor(options){
|
|
11965
|
+
super();
|
|
11966
|
+
const { shareName, library, request, independentShareFileName, mfName } = options, version = options.version || "0.0.0";
|
|
11967
|
+
this._globalName = encodeName(`${mfName}_${shareName}_${version}`);
|
|
11968
|
+
const fileName = independentShareFileName || `${version}/share-entry.js`;
|
|
11969
|
+
this._shareName = shareName, this._options = {
|
|
11970
|
+
name: shareName,
|
|
11971
|
+
request: request,
|
|
11972
|
+
library: (library ? {
|
|
11973
|
+
...library,
|
|
11974
|
+
name: this._globalName
|
|
11975
|
+
} : void 0) || {
|
|
11976
|
+
type: "global",
|
|
11977
|
+
name: this._globalName
|
|
11978
|
+
},
|
|
11979
|
+
version,
|
|
11980
|
+
fileName
|
|
11981
|
+
};
|
|
11982
|
+
}
|
|
11983
|
+
getData() {
|
|
11984
|
+
return [
|
|
11985
|
+
this._options.fileName,
|
|
11986
|
+
this._globalName,
|
|
11987
|
+
this._options.version
|
|
11988
|
+
];
|
|
11989
|
+
}
|
|
11990
|
+
raw(compiler) {
|
|
11991
|
+
let { library } = this._options;
|
|
11992
|
+
return compiler.options.output.enabledLibraryTypes.includes(library.type) || compiler.options.output.enabledLibraryTypes.push(library.type), createBuiltinPlugin(this.name, this._options);
|
|
11993
|
+
}
|
|
11994
|
+
apply(compiler) {
|
|
11995
|
+
super.apply(compiler);
|
|
11996
|
+
let shareName = this._shareName;
|
|
11997
|
+
compiler.hooks.thisCompilation.tap(this.name, (compilation)=>{
|
|
11998
|
+
compilation.hooks.processAssets.tapPromise({
|
|
11999
|
+
name: "getShareContainerFile"
|
|
12000
|
+
}, async ()=>{
|
|
12001
|
+
assert(compilation.entrypoints.get(shareName), `Can not get shared ${shareName} entryPoint!`);
|
|
12002
|
+
let remoteEntryNameChunk = compilation.namedChunks.get(shareName);
|
|
12003
|
+
assert(remoteEntryNameChunk, `Can not get shared ${shareName} chunk!`);
|
|
12004
|
+
let files = Array.from(remoteEntryNameChunk.files).filter((f)=>!f.includes(".hot-update") && !f.endsWith(".css"));
|
|
12005
|
+
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];
|
|
12006
|
+
});
|
|
12007
|
+
});
|
|
12008
|
+
}
|
|
12009
|
+
}
|
|
12010
|
+
class SharedUsedExportsOptimizerPlugin extends RspackBuiltinPlugin {
|
|
12011
|
+
name = binding_.BuiltinPluginName.SharedUsedExportsOptimizerPlugin;
|
|
12012
|
+
sharedOptions;
|
|
12013
|
+
injectUsedExports;
|
|
12014
|
+
manifestOptions;
|
|
12015
|
+
constructor(sharedOptions, injectUsedExports, manifestOptions){
|
|
12016
|
+
super(), this.sharedOptions = sharedOptions, this.injectUsedExports = injectUsedExports ?? !0, this.manifestOptions = manifestOptions ?? {};
|
|
12017
|
+
}
|
|
12018
|
+
buildOptions() {
|
|
12019
|
+
let shared = this.sharedOptions.map(([shareKey, config])=>({
|
|
12020
|
+
shareKey,
|
|
12021
|
+
treeshake: !!config.treeshake,
|
|
12022
|
+
usedExports: config.treeshake?.usedExports
|
|
12023
|
+
})), { manifestFileName, statsFileName } = getFileName(this.manifestOptions);
|
|
12024
|
+
return {
|
|
12025
|
+
shared,
|
|
12026
|
+
injectUsedExports: this.injectUsedExports,
|
|
12027
|
+
manifestFileName,
|
|
12028
|
+
statsFileName
|
|
12029
|
+
};
|
|
12030
|
+
}
|
|
12031
|
+
raw() {
|
|
12032
|
+
if (this.sharedOptions.length) return createBuiltinPlugin(this.name, this.buildOptions());
|
|
12033
|
+
}
|
|
12034
|
+
}
|
|
12035
|
+
let VIRTUAL_ENTRY = "./virtual-entry.js", VIRTUAL_ENTRY_NAME = "virtual-entry";
|
|
12036
|
+
class VirtualEntryPlugin {
|
|
12037
|
+
sharedOptions;
|
|
12038
|
+
constructor(sharedOptions){
|
|
12039
|
+
this.sharedOptions = sharedOptions;
|
|
12040
|
+
}
|
|
12041
|
+
createEntry() {
|
|
12042
|
+
let { sharedOptions } = this;
|
|
12043
|
+
return sharedOptions.reduce((acc, cur, index)=>`${acc}import shared_${index} from '${cur[0]}';\n`, "");
|
|
12044
|
+
}
|
|
12045
|
+
static entry() {
|
|
12046
|
+
return {
|
|
12047
|
+
[VIRTUAL_ENTRY_NAME]: VIRTUAL_ENTRY
|
|
12048
|
+
};
|
|
12049
|
+
}
|
|
12050
|
+
apply(compiler) {
|
|
12051
|
+
new compiler.rspack.experiments.VirtualModulesPlugin({
|
|
12052
|
+
[VIRTUAL_ENTRY]: this.createEntry()
|
|
12053
|
+
}).apply(compiler), compiler.hooks.thisCompilation.tap("RemoveVirtualEntryAsset", (compilation)=>{
|
|
12054
|
+
compilation.hooks.processAssets.tapPromise({
|
|
12055
|
+
name: "RemoveVirtualEntryAsset",
|
|
12056
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE
|
|
12057
|
+
}, async ()=>{
|
|
12058
|
+
try {
|
|
12059
|
+
let chunk = compilation.namedChunks.get(VIRTUAL_ENTRY_NAME);
|
|
12060
|
+
chunk?.files.forEach((f)=>{
|
|
12061
|
+
compilation.deleteAsset(f);
|
|
12062
|
+
});
|
|
12063
|
+
} catch (_e) {
|
|
12064
|
+
console.error("Failed to remove virtual entry file!");
|
|
12065
|
+
}
|
|
12066
|
+
});
|
|
12067
|
+
});
|
|
12068
|
+
}
|
|
12069
|
+
}
|
|
12070
|
+
let resolveOutputDir = (outputDir, shareName)=>shareName ? (0, external_node_path_namespaceObject.join)(outputDir, encodeName(shareName)) : outputDir;
|
|
12071
|
+
class IndependentSharedPlugin {
|
|
12072
|
+
mfName;
|
|
12073
|
+
shared;
|
|
12074
|
+
library;
|
|
12075
|
+
sharedOptions;
|
|
12076
|
+
outputDir;
|
|
12077
|
+
plugins;
|
|
12078
|
+
treeshake;
|
|
12079
|
+
manifest;
|
|
12080
|
+
buildAssets = {};
|
|
12081
|
+
injectUsedExports;
|
|
12082
|
+
treeshakeSharedExcludedPlugins;
|
|
12083
|
+
name = "IndependentSharedPlugin";
|
|
12084
|
+
constructor(options){
|
|
12085
|
+
const { outputDir, plugins, treeshake, shared, name, manifest, injectUsedExports, library, treeshakeSharedExcludedPlugins } = options;
|
|
12086
|
+
this.shared = shared, this.mfName = name, this.outputDir = outputDir || "independent-packages", this.plugins = plugins || [], this.treeshake = treeshake, this.manifest = manifest, this.injectUsedExports = injectUsedExports ?? !0, this.library = library, this.treeshakeSharedExcludedPlugins = treeshakeSharedExcludedPlugins || [], this.sharedOptions = parseOptions(shared, (item, key)=>{
|
|
12087
|
+
if ("string" != typeof item) throw Error(`Unexpected array in shared configuration for key "${key}"`);
|
|
12088
|
+
return item !== key && isRequiredVersion(item) ? {
|
|
12089
|
+
import: key,
|
|
12090
|
+
requiredVersion: item
|
|
12091
|
+
} : {
|
|
12092
|
+
import: item
|
|
12093
|
+
};
|
|
12094
|
+
}, (item)=>item);
|
|
12095
|
+
}
|
|
12096
|
+
apply(compiler) {
|
|
12097
|
+
let { manifest } = this, runCount = 0;
|
|
12098
|
+
compiler.hooks.beforeRun.tapPromise("IndependentSharedPlugin", async ()=>{
|
|
12099
|
+
!runCount && (await this.createIndependentCompilers(compiler), runCount++);
|
|
12100
|
+
}), compiler.hooks.watchRun.tapPromise("IndependentSharedPlugin", async ()=>{
|
|
12101
|
+
!runCount && (await this.createIndependentCompilers(compiler), runCount++);
|
|
12102
|
+
}), compiler.hooks.shutdown.tapAsync("IndependentSharedPlugin", (callback)=>{
|
|
12103
|
+
callback();
|
|
12104
|
+
}), manifest && compiler.hooks.compilation.tap("IndependentSharedPlugin", (compilation)=>{
|
|
12105
|
+
compilation.hooks.processAssets.tapPromise({
|
|
12106
|
+
name: "injectBuildAssets",
|
|
12107
|
+
stage: compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
|
|
12108
|
+
}, async ()=>{
|
|
12109
|
+
let { statsFileName, manifestFileName } = getFileName(manifest), injectBuildAssetsIntoStatsOrManifest = (filename)=>{
|
|
12110
|
+
let stats = compilation.getAsset(filename);
|
|
12111
|
+
if (!stats) return;
|
|
12112
|
+
let statsContent = JSON.parse(stats.source.source().toString()), { shared } = statsContent;
|
|
12113
|
+
Object.entries(this.buildAssets).forEach(([key, item])=>{
|
|
12114
|
+
let targetShared = shared.find((s)=>s.name === key);
|
|
12115
|
+
targetShared && item.forEach(([entry, version, globalName])=>{
|
|
12116
|
+
version === targetShared.version && (targetShared.fallback = entry, targetShared.fallbackName = globalName);
|
|
12117
|
+
});
|
|
12118
|
+
}), compilation.updateAsset(filename, new compiler.webpack.sources.RawSource(JSON.stringify(statsContent)));
|
|
12119
|
+
};
|
|
12120
|
+
injectBuildAssetsIntoStatsOrManifest(statsFileName), injectBuildAssetsIntoStatsOrManifest(manifestFileName);
|
|
12121
|
+
});
|
|
12122
|
+
});
|
|
12123
|
+
}
|
|
12124
|
+
async createIndependentCompilers(parentCompiler) {
|
|
12125
|
+
let { sharedOptions, buildAssets, outputDir } = this;
|
|
12126
|
+
console.log("🚀 Start creating a standalone compiler...");
|
|
12127
|
+
let shareRequestsMap = await this.createIndependentCompiler(parentCompiler);
|
|
12128
|
+
await Promise.all(sharedOptions.map(async ([shareName, shareConfig])=>{
|
|
12129
|
+
if (!shareConfig.treeshake || !1 === shareConfig.import) return;
|
|
12130
|
+
let shareRequests = shareRequestsMap[shareName].requests;
|
|
12131
|
+
await Promise.all(shareRequests.map(async ([request, version])=>{
|
|
12132
|
+
let sharedConfig = sharedOptions.find(([name])=>name === shareName)?.[1], [shareFileName, globalName, sharedVersion] = await this.createIndependentCompiler(parentCompiler, {
|
|
12133
|
+
shareRequestsMap,
|
|
12134
|
+
currentShare: {
|
|
12135
|
+
shareName,
|
|
12136
|
+
version,
|
|
12137
|
+
request,
|
|
12138
|
+
independentShareFileName: sharedConfig?.treeshake?.filename
|
|
12139
|
+
}
|
|
12140
|
+
});
|
|
12141
|
+
"string" == typeof shareFileName && (buildAssets[shareName] ||= [], buildAssets[shareName].push([
|
|
12142
|
+
(0, external_node_path_namespaceObject.join)(resolveOutputDir(outputDir, shareName), shareFileName),
|
|
12143
|
+
sharedVersion,
|
|
12144
|
+
globalName
|
|
12145
|
+
]));
|
|
12146
|
+
}));
|
|
12147
|
+
})), console.log("✅ All independent packages have been compiled successfully");
|
|
12148
|
+
}
|
|
12149
|
+
async createIndependentCompiler(parentCompiler, extraOptions) {
|
|
12150
|
+
let extraPlugin, { mfName, plugins, outputDir, sharedOptions, treeshake, library, treeshakeSharedExcludedPlugins } = this, outputDirWithShareName = resolveOutputDir(outputDir, extraOptions?.currentShare?.shareName || ""), parentConfig = parentCompiler.options, finalPlugins = [], rspack = parentCompiler.rspack;
|
|
12151
|
+
extraPlugin = extraOptions ? new SharedContainerPlugin({
|
|
12152
|
+
mfName,
|
|
12153
|
+
library,
|
|
12154
|
+
...extraOptions.currentShare
|
|
12155
|
+
}) : new CollectSharedEntryPlugin({
|
|
12156
|
+
sharedOptions,
|
|
12157
|
+
shareScope: "default"
|
|
12158
|
+
}), (parentConfig.plugins || []).forEach((plugin)=>{
|
|
12159
|
+
void 0 !== plugin && "string" != typeof plugin && ((plugin, excludedPlugins = [])=>{
|
|
12160
|
+
if (!plugin) return !0;
|
|
12161
|
+
let pluginName = plugin.name || plugin.constructor?.name;
|
|
12162
|
+
return !pluginName || ![
|
|
12163
|
+
"TreeShakeSharedPlugin",
|
|
12164
|
+
"IndependentSharedPlugin",
|
|
12165
|
+
"ModuleFederationPlugin",
|
|
12166
|
+
"SharedUsedExportsOptimizerPlugin",
|
|
12167
|
+
"HtmlWebpackPlugin",
|
|
12168
|
+
...excludedPlugins
|
|
12169
|
+
].includes(pluginName);
|
|
12170
|
+
})(plugin, treeshakeSharedExcludedPlugins) && finalPlugins.push(plugin);
|
|
12171
|
+
}), plugins.forEach((plugin)=>{
|
|
12172
|
+
finalPlugins.push(plugin);
|
|
12173
|
+
}), finalPlugins.push(extraPlugin), finalPlugins.push(new ConsumeSharedPlugin({
|
|
12174
|
+
consumes: sharedOptions.filter(([key, options])=>extraOptions?.currentShare.shareName !== (options.shareKey || key)).map(([key, options])=>({
|
|
12175
|
+
[key]: {
|
|
12176
|
+
import: !extraOptions && options.import,
|
|
12177
|
+
shareKey: options.shareKey || key,
|
|
12178
|
+
shareScope: options.shareScope,
|
|
12179
|
+
requiredVersion: options.requiredVersion,
|
|
12180
|
+
strictVersion: options.strictVersion,
|
|
12181
|
+
singleton: options.singleton,
|
|
12182
|
+
packageName: options.packageName,
|
|
12183
|
+
eager: options.eager
|
|
12184
|
+
}
|
|
12185
|
+
})),
|
|
12186
|
+
enhanced: !0
|
|
12187
|
+
})), treeshake && finalPlugins.push(new SharedUsedExportsOptimizerPlugin(sharedOptions, this.injectUsedExports)), finalPlugins.push(new VirtualEntryPlugin(sharedOptions));
|
|
12188
|
+
let fullOutputDir = (0, external_node_path_namespaceObject.resolve)(parentCompiler.outputPath, outputDirWithShareName), compilerConfig = {
|
|
12189
|
+
...parentConfig,
|
|
12190
|
+
mode: parentConfig.mode || "development",
|
|
12191
|
+
entry: VirtualEntryPlugin.entry,
|
|
12192
|
+
output: {
|
|
12193
|
+
path: fullOutputDir,
|
|
12194
|
+
clean: !0,
|
|
12195
|
+
publicPath: parentConfig.output?.publicPath || "auto"
|
|
12196
|
+
},
|
|
12197
|
+
plugins: finalPlugins,
|
|
12198
|
+
optimization: {
|
|
12199
|
+
...parentConfig.optimization,
|
|
12200
|
+
splitChunks: !1
|
|
12201
|
+
}
|
|
12202
|
+
}, compiler = rspack.rspack(compilerConfig);
|
|
12203
|
+
compiler.inputFileSystem = parentCompiler.inputFileSystem, compiler.outputFileSystem = parentCompiler.outputFileSystem, compiler.intermediateFileSystem = parentCompiler.intermediateFileSystem;
|
|
12204
|
+
let { currentShare } = extraOptions || {};
|
|
12205
|
+
return new Promise((resolve, reject)=>{
|
|
12206
|
+
compiler.run((err, stats)=>{
|
|
12207
|
+
if (err || stats?.hasErrors()) {
|
|
12208
|
+
let target = currentShare ? currentShare.shareName : "收集依赖";
|
|
12209
|
+
console.error(`❌ ${target} 编译失败:`, err || stats.toJson().errors.map((e)=>e.message).join("\n")), reject(err || Error(`${target} 编译失败`));
|
|
12210
|
+
return;
|
|
12211
|
+
}
|
|
12212
|
+
currentShare && console.log(`✅ 独立包 ${currentShare.shareName} 编译成功`), stats && (currentShare && console.log(`📊 ${currentShare.shareName} 编译统计:`), console.log(stats.toString({
|
|
12213
|
+
colors: !0,
|
|
12214
|
+
chunks: !1,
|
|
12215
|
+
modules: !1
|
|
12216
|
+
}))), resolve(extraPlugin.getData());
|
|
12217
|
+
});
|
|
12218
|
+
});
|
|
12219
|
+
}
|
|
12220
|
+
}
|
|
12221
|
+
class TreeShakeSharedPlugin {
|
|
12222
|
+
mfConfig;
|
|
12223
|
+
outputDir;
|
|
12224
|
+
plugins;
|
|
12225
|
+
reshake;
|
|
12226
|
+
_independentSharePlugin;
|
|
12227
|
+
name = "TreeShakeSharedPlugin";
|
|
12228
|
+
constructor(options){
|
|
12229
|
+
const { mfConfig, plugins, reshake } = options;
|
|
12230
|
+
this.mfConfig = mfConfig, this.outputDir = mfConfig.independentShareDir || "independent-packages", this.plugins = plugins, this.reshake = !!reshake;
|
|
12231
|
+
}
|
|
12232
|
+
apply(compiler) {
|
|
12233
|
+
let { mfConfig, outputDir, plugins, reshake } = this, { name, shared, library } = mfConfig;
|
|
12234
|
+
if (!shared) return;
|
|
12235
|
+
let sharedOptions = normalizeSharedOptions(shared);
|
|
12236
|
+
sharedOptions.length && sharedOptions.some(([_, config])=>config.treeshake && !1 !== config.import) && (reshake || new SharedUsedExportsOptimizerPlugin(sharedOptions, mfConfig.injectUsedExports, mfConfig.manifest).apply(compiler), this._independentSharePlugin = new IndependentSharedPlugin({
|
|
12237
|
+
name: name,
|
|
12238
|
+
shared: shared,
|
|
12239
|
+
outputDir,
|
|
12240
|
+
plugins,
|
|
12241
|
+
treeshake: reshake,
|
|
12242
|
+
library,
|
|
12243
|
+
manifest: mfConfig.manifest,
|
|
12244
|
+
treeshakeSharedExcludedPlugins: mfConfig.treeshakeSharedExcludedPlugins
|
|
12245
|
+
}), this._independentSharePlugin.apply(compiler));
|
|
12246
|
+
}
|
|
12247
|
+
get buildAssets() {
|
|
12248
|
+
return this._independentSharePlugin?.buildAssets || {};
|
|
12249
|
+
}
|
|
12250
|
+
}
|
|
12251
|
+
let ModuleFederationRuntimePlugin = base_create(binding_.BuiltinPluginName.ModuleFederationRuntimePlugin, (options = {})=>options);
|
|
12252
|
+
function getRemoteInfos(options) {
|
|
12253
|
+
if (!options.remotes) return {};
|
|
12254
|
+
let remoteType = options.remoteType || (options.library ? options.library.type : "script"), remotes = parseOptions(options.remotes, (item)=>({
|
|
12255
|
+
external: Array.isArray(item) ? item : [
|
|
12256
|
+
item
|
|
12257
|
+
],
|
|
12258
|
+
shareScope: options.shareScope || "default"
|
|
12259
|
+
}), (item)=>({
|
|
12260
|
+
external: Array.isArray(item.external) ? item.external : [
|
|
12261
|
+
item.external
|
|
12262
|
+
],
|
|
12263
|
+
shareScope: item.shareScope || options.shareScope || "default"
|
|
12264
|
+
})), remoteInfos = {};
|
|
12265
|
+
for (let [key, config] of remotes)for (let external of config.external){
|
|
12266
|
+
let [externalType, externalRequest] = function(external) {
|
|
12267
|
+
let result = function(external) {
|
|
12268
|
+
if (/^[a-z0-9-]+ /.test(external)) {
|
|
12269
|
+
let idx = external.indexOf(" ");
|
|
12270
|
+
return [
|
|
12271
|
+
external.slice(0, idx),
|
|
12272
|
+
external.slice(idx + 1)
|
|
12273
|
+
];
|
|
12274
|
+
}
|
|
12275
|
+
return null;
|
|
12276
|
+
}(external);
|
|
12277
|
+
return null === result ? [
|
|
12278
|
+
remoteType,
|
|
12279
|
+
external
|
|
12280
|
+
] : result;
|
|
12281
|
+
}(external);
|
|
12282
|
+
if (remoteInfos[key] ??= [], "script" === externalType) {
|
|
12283
|
+
let [url, global] = function(urlAndGlobal) {
|
|
12284
|
+
let index = urlAndGlobal.indexOf("@");
|
|
12285
|
+
return index <= 0 || index === urlAndGlobal.length - 1 ? null : [
|
|
12286
|
+
urlAndGlobal.substring(index + 1),
|
|
12287
|
+
urlAndGlobal.substring(0, index)
|
|
12288
|
+
];
|
|
12289
|
+
}(externalRequest);
|
|
12290
|
+
remoteInfos[key].push({
|
|
12291
|
+
alias: key,
|
|
12292
|
+
name: global,
|
|
12293
|
+
entry: url,
|
|
12294
|
+
externalType,
|
|
12295
|
+
shareScope: config.shareScope
|
|
12296
|
+
});
|
|
12297
|
+
} else remoteInfos[key].push({
|
|
12298
|
+
alias: key,
|
|
12299
|
+
name: void 0,
|
|
12300
|
+
entry: void 0,
|
|
12301
|
+
externalType,
|
|
12302
|
+
shareScope: config.shareScope
|
|
12303
|
+
});
|
|
12304
|
+
}
|
|
12305
|
+
return remoteInfos;
|
|
12306
|
+
}
|
|
11884
12307
|
class ContainerPlugin extends RspackBuiltinPlugin {
|
|
11885
12308
|
name = binding_.BuiltinPluginName.ContainerPlugin;
|
|
11886
12309
|
_options;
|
|
@@ -11889,7 +12312,7 @@ Help:
|
|
|
11889
12312
|
name: options.name,
|
|
11890
12313
|
shareScope: options.shareScope || "default",
|
|
11891
12314
|
library: options.library || {
|
|
11892
|
-
type: "
|
|
12315
|
+
type: "global",
|
|
11893
12316
|
name: options.name
|
|
11894
12317
|
},
|
|
11895
12318
|
runtime: options.runtime,
|
|
@@ -11972,7 +12395,7 @@ Help:
|
|
|
11972
12395
|
let _options = JSON.stringify(options || {});
|
|
11973
12396
|
return binding_default().transform(source, _options);
|
|
11974
12397
|
}
|
|
11975
|
-
let exports_rspackVersion = "1.6.7-canary-
|
|
12398
|
+
let exports_rspackVersion = "1.6.7-canary-f7e6adf4-20251211131042", exports_version = "5.75.0", exports_WebpackError = Error, sources = __webpack_require__("webpack-sources"), exports_config = {
|
|
11976
12399
|
getNormalizedRspackOptions: getNormalizedRspackOptions,
|
|
11977
12400
|
applyRspackOptionsDefaults: applyRspackOptionsDefaults,
|
|
11978
12401
|
getNormalizedWebpackOptions: getNormalizedRspackOptions,
|
|
@@ -12015,11 +12438,12 @@ Help:
|
|
|
12015
12438
|
ContainerReferencePlugin: ContainerReferencePlugin,
|
|
12016
12439
|
ModuleFederationPlugin: class {
|
|
12017
12440
|
_options;
|
|
12441
|
+
_treeShakeSharedPlugin;
|
|
12018
12442
|
constructor(_options){
|
|
12019
12443
|
this._options = _options;
|
|
12020
12444
|
}
|
|
12021
12445
|
apply(compiler) {
|
|
12022
|
-
var options;
|
|
12446
|
+
var options, options1;
|
|
12023
12447
|
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", {
|
|
12024
12448
|
paths: [
|
|
12025
12449
|
runtimeToolsPath
|
|
@@ -12033,101 +12457,54 @@ Help:
|
|
|
12033
12457
|
bundlerRuntime: bundlerRuntimePath,
|
|
12034
12458
|
runtime: runtimePath
|
|
12035
12459
|
});
|
|
12036
|
-
|
|
12460
|
+
compiler.options.resolve.alias = {
|
|
12037
12461
|
"@module-federation/runtime-tools": paths.runtimeTools,
|
|
12038
12462
|
"@module-federation/runtime": paths.runtime,
|
|
12039
12463
|
...compiler.options.resolve.alias
|
|
12040
|
-
},
|
|
12041
|
-
|
|
12042
|
-
|
|
12043
|
-
|
|
12044
|
-
|
|
12045
|
-
|
|
12046
|
-
|
|
12047
|
-
|
|
12048
|
-
|
|
12049
|
-
|
|
12050
|
-
|
|
12051
|
-
|
|
12052
|
-
|
|
12053
|
-
|
|
12054
|
-
|
|
12055
|
-
|
|
12056
|
-
|
|
12057
|
-
|
|
12058
|
-
|
|
12059
|
-
|
|
12060
|
-
|
|
12464
|
+
}, ((options1 = this._options).shared ? parseOptions(options1.shared, (item, key)=>{
|
|
12465
|
+
if ("string" != typeof item) throw Error("Unexpected array in shared");
|
|
12466
|
+
return item !== key && isRequiredVersion(item) ? {
|
|
12467
|
+
import: key,
|
|
12468
|
+
requiredVersion: item
|
|
12469
|
+
} : {
|
|
12470
|
+
import: item
|
|
12471
|
+
};
|
|
12472
|
+
}, (item)=>item) : []).filter(([, config])=>config.treeshake).length > 0 && (this._treeShakeSharedPlugin = new TreeShakeSharedPlugin({
|
|
12473
|
+
mfConfig: this._options,
|
|
12474
|
+
reshake: !1
|
|
12475
|
+
}), this._treeShakeSharedPlugin.apply(compiler));
|
|
12476
|
+
let runtimePluginApplied = !1;
|
|
12477
|
+
compiler.hooks.beforeRun.tapPromise({
|
|
12478
|
+
name: "ModuleFederationPlugin",
|
|
12479
|
+
stage: 100
|
|
12480
|
+
}, async ()=>{
|
|
12481
|
+
runtimePluginApplied || (runtimePluginApplied = !0, new ModuleFederationRuntimePlugin({
|
|
12482
|
+
entryRuntime: function(paths, options, compiler, treeshakeShareFallbacks) {
|
|
12483
|
+
let runtimePlugins = options.runtimePlugins ?? [], remoteInfos = getRemoteInfos(options), runtimePluginImports = [], runtimePluginVars = [], libraryType = options.library?.type || "var";
|
|
12484
|
+
for(let i = 0; i < runtimePlugins.length; i++){
|
|
12485
|
+
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;
|
|
12486
|
+
runtimePluginImports.push(`import ${runtimePluginVar} from ${JSON.stringify(pluginPath)}`);
|
|
12487
|
+
let paramsCode = void 0 === pluginParams ? "undefined" : JSON.stringify(pluginParams);
|
|
12488
|
+
runtimePluginVars.push(`${runtimePluginVar}(${paramsCode})`);
|
|
12489
|
+
}
|
|
12490
|
+
let content = [
|
|
12491
|
+
`import __module_federation_bundler_runtime__ from ${JSON.stringify(paths.bundlerRuntime)}`,
|
|
12492
|
+
...runtimePluginImports,
|
|
12493
|
+
`const __module_federation_runtime_plugins__ = [${runtimePluginVars.join(", ")}]`,
|
|
12494
|
+
`const __module_federation_remote_infos__ = ${JSON.stringify(remoteInfos)}`,
|
|
12495
|
+
`const __module_federation_container_name__ = ${JSON.stringify(options.name ?? compiler.options.output.uniqueName)}`,
|
|
12496
|
+
`const __module_federation_share_strategy__ = ${JSON.stringify(options.shareStrategy ?? "version-first")}`,
|
|
12497
|
+
`const __module_federation_share_fallbacks__ = ${JSON.stringify(treeshakeShareFallbacks)}`,
|
|
12498
|
+
`const __module_federation_library_type__ = ${JSON.stringify(libraryType)}`,
|
|
12499
|
+
compiler.webpack.Template.getFunctionContent(__webpack_require__("./moduleFederationDefaultRuntime.js"))
|
|
12500
|
+
].join(";");
|
|
12501
|
+
return `@module-federation/runtime/rspack.js!=!data:text/javascript,${content}`;
|
|
12502
|
+
}(paths, this._options, compiler, this._treeShakeSharedPlugin?.buildAssets || {})
|
|
12503
|
+
}).apply(compiler));
|
|
12504
|
+
}), new webpack.container.ModuleFederationPluginV1({
|
|
12061
12505
|
...this._options,
|
|
12062
12506
|
enhanced: !0
|
|
12063
|
-
}).apply(compiler), this._options.manifest)
|
|
12064
|
-
let manifestOptions = !0 === this._options.manifest ? {} : {
|
|
12065
|
-
...this._options.manifest
|
|
12066
|
-
}, containerName = manifestOptions.name ?? this._options.name, globalName = manifestOptions.globalName ?? function(library) {
|
|
12067
|
-
if (!library) return;
|
|
12068
|
-
let libName = library.name;
|
|
12069
|
-
if (libName) {
|
|
12070
|
-
if ("string" == typeof libName) return libName;
|
|
12071
|
-
if (Array.isArray(libName)) return libName[0];
|
|
12072
|
-
if ("object" == typeof libName) return libName.root?.[0] ?? libName.amd ?? libName.commonjs ?? void 0;
|
|
12073
|
-
}
|
|
12074
|
-
}(this._options.library) ?? containerName, remoteAliasMap = Object.entries(getRemoteInfos(this._options)).reduce((sum, cur)=>{
|
|
12075
|
-
if (cur[1].length > 1) return sum;
|
|
12076
|
-
let { entry, alias, name } = cur[1][0];
|
|
12077
|
-
return entry && name && (sum[alias] = {
|
|
12078
|
-
name,
|
|
12079
|
-
entry
|
|
12080
|
-
}), sum;
|
|
12081
|
-
}, {}), manifestExposes = function(exposes) {
|
|
12082
|
-
if (!exposes) return;
|
|
12083
|
-
let result = parseOptions(exposes, (value, key)=>({
|
|
12084
|
-
import: Array.isArray(value) ? value : [
|
|
12085
|
-
value
|
|
12086
|
-
],
|
|
12087
|
-
name: void 0
|
|
12088
|
-
}), (value)=>({
|
|
12089
|
-
import: Array.isArray(value.import) ? value.import : [
|
|
12090
|
-
value.import
|
|
12091
|
-
],
|
|
12092
|
-
name: value.name ?? void 0
|
|
12093
|
-
})).map(([exposeKey, info])=>{
|
|
12094
|
-
let exposeName = info.name ?? exposeKey.replace(/^\.\//, "");
|
|
12095
|
-
return {
|
|
12096
|
-
path: exposeKey,
|
|
12097
|
-
name: exposeName
|
|
12098
|
-
};
|
|
12099
|
-
});
|
|
12100
|
-
return result.length > 0 ? result : void 0;
|
|
12101
|
-
}(this._options.exposes);
|
|
12102
|
-
void 0 === manifestOptions.exposes && manifestExposes && (manifestOptions.exposes = manifestExposes);
|
|
12103
|
-
let manifestShared = function(shared) {
|
|
12104
|
-
if (!shared) return;
|
|
12105
|
-
let result = parseOptions(shared, (item, key)=>{
|
|
12106
|
-
if ("string" != typeof item) throw Error("Unexpected array in shared");
|
|
12107
|
-
return item !== key && isRequiredVersion(item) ? {
|
|
12108
|
-
import: key,
|
|
12109
|
-
requiredVersion: item
|
|
12110
|
-
} : {
|
|
12111
|
-
import: item
|
|
12112
|
-
};
|
|
12113
|
-
}, (item)=>item).map(([key, config])=>{
|
|
12114
|
-
let name = config.shareKey || key, version = "string" == typeof config.version ? config.version : void 0;
|
|
12115
|
-
return {
|
|
12116
|
-
name,
|
|
12117
|
-
version,
|
|
12118
|
-
requiredVersion: "string" == typeof config.requiredVersion ? config.requiredVersion : void 0,
|
|
12119
|
-
singleton: config.singleton
|
|
12120
|
-
};
|
|
12121
|
-
});
|
|
12122
|
-
return result.length > 0 ? result : void 0;
|
|
12123
|
-
}(this._options.shared);
|
|
12124
|
-
void 0 === manifestOptions.shared && manifestShared && (manifestOptions.shared = manifestShared), new ModuleFederationManifestPlugin({
|
|
12125
|
-
...manifestOptions,
|
|
12126
|
-
name: containerName,
|
|
12127
|
-
globalName,
|
|
12128
|
-
remoteAliasMap
|
|
12129
|
-
}).apply(compiler);
|
|
12130
|
-
}
|
|
12507
|
+
}).apply(compiler), this._options.manifest && new ModuleFederationManifestPlugin(this._options).apply(compiler);
|
|
12131
12508
|
}
|
|
12132
12509
|
},
|
|
12133
12510
|
ModuleFederationPluginV1: class {
|
|
@@ -12164,6 +12541,7 @@ Help:
|
|
|
12164
12541
|
}
|
|
12165
12542
|
}, sharing = {
|
|
12166
12543
|
ProvideSharedPlugin: ProvideSharedPlugin,
|
|
12544
|
+
TreeShakeSharedPlugin: TreeShakeSharedPlugin,
|
|
12167
12545
|
ConsumeSharedPlugin: ConsumeSharedPlugin,
|
|
12168
12546
|
SharePlugin: SharePlugin
|
|
12169
12547
|
}, exports_experiments = {
|