@module-federation/nextjs-mf 8.8.71 → 8.8.72
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/src/plugins/NextFederationPlugin/FederatedStatsCompatibilityPlugin.d.mts +22 -0
- package/dist/src/plugins/NextFederationPlugin/FederatedStatsCompatibilityPlugin.d.ts +22 -0
- package/dist/src/plugins/NextFederationPlugin/FederatedStatsCompatibilityPlugin.js +43 -0
- package/dist/src/plugins/NextFederationPlugin/FederatedStatsCompatibilityPlugin.js.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/FederatedStatsCompatibilityPlugin.mjs +42 -0
- package/dist/src/plugins/NextFederationPlugin/FederatedStatsCompatibilityPlugin.mjs.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js +7 -1
- package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.mjs +7 -1
- package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.mjs.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/index.js +2 -5
- package/dist/src/plugins/NextFederationPlugin/index.js.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/index.mjs +2 -5
- package/dist/src/plugins/NextFederationPlugin/index.mjs.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/manifest-options.d.mts +4 -0
- package/dist/src/plugins/NextFederationPlugin/manifest-options.d.ts +4 -0
- package/dist/src/plugins/NextFederationPlugin/manifest-options.js +13 -0
- package/dist/src/plugins/NextFederationPlugin/manifest-options.js.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/manifest-options.mjs +12 -0
- package/dist/src/plugins/NextFederationPlugin/manifest-options.mjs.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/set-options.d.mts +1 -11
- package/dist/src/plugins/NextFederationPlugin/set-options.d.ts +1 -11
- package/dist/src/plugins/NextFederationPlugin/set-options.js.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/set-options.mjs.map +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Compiler, WebpackPluginInstance } from 'webpack';
|
|
2
|
+
import { type Manifest, type moduleFederationPlugin } from '@module-federation/sdk';
|
|
3
|
+
type FederatedStatsCompatibilityPluginOptions = {
|
|
4
|
+
filenames: string[];
|
|
5
|
+
manifest: moduleFederationPlugin.ModuleFederationPluginOptions['manifest'];
|
|
6
|
+
};
|
|
7
|
+
export declare const createFederatedStats: (manifest: Manifest) => {
|
|
8
|
+
sharedModules: any[];
|
|
9
|
+
federatedModules: {
|
|
10
|
+
remote: string;
|
|
11
|
+
entry: string;
|
|
12
|
+
sharedModules: any[];
|
|
13
|
+
exposes: Record<string, string[]>;
|
|
14
|
+
remoteModules: {};
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
17
|
+
export declare class FederatedStatsCompatibilityPlugin implements WebpackPluginInstance {
|
|
18
|
+
private readonly options;
|
|
19
|
+
constructor(options: FederatedStatsCompatibilityPluginOptions);
|
|
20
|
+
apply(compiler: Compiler): void;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Compiler, WebpackPluginInstance } from 'webpack';
|
|
2
|
+
import { type Manifest, type moduleFederationPlugin } from '@module-federation/sdk';
|
|
3
|
+
type FederatedStatsCompatibilityPluginOptions = {
|
|
4
|
+
filenames: string[];
|
|
5
|
+
manifest: moduleFederationPlugin.ModuleFederationPluginOptions['manifest'];
|
|
6
|
+
};
|
|
7
|
+
export declare const createFederatedStats: (manifest: Manifest) => {
|
|
8
|
+
sharedModules: any[];
|
|
9
|
+
federatedModules: {
|
|
10
|
+
remote: string;
|
|
11
|
+
entry: string;
|
|
12
|
+
sharedModules: any[];
|
|
13
|
+
exposes: Record<string, string[]>;
|
|
14
|
+
remoteModules: {};
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
17
|
+
export declare class FederatedStatsCompatibilityPlugin implements WebpackPluginInstance {
|
|
18
|
+
private readonly options;
|
|
19
|
+
constructor(options: FederatedStatsCompatibilityPluginOptions);
|
|
20
|
+
apply(compiler: Compiler): void;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const require_runtime = require('../../../_virtual/_rolldown/runtime.js');
|
|
2
|
+
let _module_federation_sdk = require("@module-federation/sdk");
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/NextFederationPlugin/FederatedStatsCompatibilityPlugin.ts
|
|
5
|
+
const createFederatedStats = (manifest) => {
|
|
6
|
+
const exposes = {};
|
|
7
|
+
for (const expose of manifest.exposes) exposes[expose.path || `./${expose.name}`] = [...expose.assets.js.sync, ...expose.assets.css.sync];
|
|
8
|
+
return {
|
|
9
|
+
sharedModules: [],
|
|
10
|
+
federatedModules: [{
|
|
11
|
+
remote: manifest.name,
|
|
12
|
+
entry: (0, _module_federation_sdk.simpleJoinRemoteEntry)(manifest.metaData.remoteEntry.path, manifest.metaData.remoteEntry.name),
|
|
13
|
+
sharedModules: [],
|
|
14
|
+
exposes,
|
|
15
|
+
remoteModules: {}
|
|
16
|
+
}]
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
var FederatedStatsCompatibilityPlugin = class {
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.options = options;
|
|
22
|
+
}
|
|
23
|
+
apply(compiler) {
|
|
24
|
+
compiler.hooks.thisCompilation.tap("FederatedStatsCompatibilityPlugin", (compilation) => {
|
|
25
|
+
compilation.hooks.processAssets.tap({
|
|
26
|
+
name: "FederatedStatsCompatibilityPlugin",
|
|
27
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT
|
|
28
|
+
}, () => {
|
|
29
|
+
const manifestFilename = (0, _module_federation_sdk.getManifestFileName)(this.options.manifest).manifestFileName;
|
|
30
|
+
const manifestAsset = compilation.getAsset(manifestFilename);
|
|
31
|
+
if (!manifestAsset) throw new Error(`Cannot emit federated-stats.json because ${manifestFilename} was not generated`);
|
|
32
|
+
const manifest = JSON.parse(manifestAsset.source.source().toString());
|
|
33
|
+
const source = new compiler.webpack.sources.RawSource(JSON.stringify(createFederatedStats(manifest)));
|
|
34
|
+
for (const filename of this.options.filenames) if (compilation.getAsset(filename)) compilation.updateAsset(filename, source);
|
|
35
|
+
else compilation.emitAsset(filename, source);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
exports.FederatedStatsCompatibilityPlugin = FederatedStatsCompatibilityPlugin;
|
|
43
|
+
//# sourceMappingURL=FederatedStatsCompatibilityPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FederatedStatsCompatibilityPlugin.js","names":[],"sources":["../../../../src/plugins/NextFederationPlugin/FederatedStatsCompatibilityPlugin.ts"],"sourcesContent":["import type { Compiler, WebpackPluginInstance } from 'webpack';\nimport {\n getManifestFileName,\n simpleJoinRemoteEntry,\n type Manifest,\n type moduleFederationPlugin,\n} from '@module-federation/sdk';\n\ntype FederatedStatsCompatibilityPluginOptions = {\n filenames: string[];\n manifest: moduleFederationPlugin.ModuleFederationPluginOptions['manifest'];\n};\n\nexport const createFederatedStats = (manifest: Manifest) => {\n const exposes: Record<string, string[]> = {};\n\n for (const expose of manifest.exposes) {\n exposes[expose.path || `./${expose.name}`] = [\n ...expose.assets.js.sync,\n ...expose.assets.css.sync,\n ];\n }\n\n return {\n sharedModules: [],\n federatedModules: [\n {\n remote: manifest.name,\n entry: simpleJoinRemoteEntry(\n manifest.metaData.remoteEntry.path,\n manifest.metaData.remoteEntry.name,\n ),\n sharedModules: [],\n exposes,\n remoteModules: {},\n },\n ],\n };\n};\n\nexport class FederatedStatsCompatibilityPlugin implements WebpackPluginInstance {\n private readonly options: FederatedStatsCompatibilityPluginOptions;\n\n constructor(options: FederatedStatsCompatibilityPluginOptions) {\n this.options = options;\n }\n\n apply(compiler: Compiler): void {\n compiler.hooks.thisCompilation.tap(\n 'FederatedStatsCompatibilityPlugin',\n (compilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: 'FederatedStatsCompatibilityPlugin',\n stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT,\n },\n () => {\n const manifestFilename = getManifestFileName(\n this.options.manifest,\n ).manifestFileName;\n const manifestAsset = compilation.getAsset(manifestFilename);\n if (!manifestAsset) {\n throw new Error(\n `Cannot emit federated-stats.json because ${manifestFilename} was not generated`,\n );\n }\n\n const manifest = JSON.parse(\n manifestAsset.source.source().toString(),\n ) as Manifest;\n const source = new compiler.webpack.sources.RawSource(\n JSON.stringify(createFederatedStats(manifest)),\n );\n\n for (const filename of this.options.filenames) {\n if (compilation.getAsset(filename)) {\n compilation.updateAsset(filename, source);\n } else {\n compilation.emitAsset(filename, source);\n }\n }\n },\n );\n },\n );\n }\n}\n"],"mappings":";;;;AAaA,MAAa,wBAAwB,aAAuB;CAC1D,MAAM,UAAoC,EAAE;AAE5C,MAAK,MAAM,UAAU,SAAS,QAC5B,SAAQ,OAAO,QAAQ,KAAK,OAAO,UAAU,CAC3C,GAAG,OAAO,OAAO,GAAG,MACpB,GAAG,OAAO,OAAO,IAAI,KACtB;AAGH,QAAO;EACL,eAAe,EAAE;EACjB,kBAAkB,CAChB;GACE,QAAQ,SAAS;GACjB,yDACE,SAAS,SAAS,YAAY,MAC9B,SAAS,SAAS,YAAY,KAC/B;GACD,eAAe,EAAE;GACjB;GACA,eAAe,EAAE;GAClB,CACF;EACF;;AAGH,IAAa,oCAAb,MAAgF;CAG9E,YAAY,SAAmD;AAC7D,OAAK,UAAU;;CAGjB,MAAM,UAA0B;AAC9B,WAAS,MAAM,gBAAgB,IAC7B,sCACC,gBAAgB;AACf,eAAY,MAAM,cAAc,IAC9B;IACE,MAAM;IACN,OAAO,SAAS,QAAQ,YAAY;IACrC,QACK;IACJ,MAAM,mEACJ,KAAK,QAAQ,SACd,CAAC;IACF,MAAM,gBAAgB,YAAY,SAAS,iBAAiB;AAC5D,QAAI,CAAC,cACH,OAAM,IAAI,MACR,4CAA4C,iBAAiB,oBAC9D;IAGH,MAAM,WAAW,KAAK,MACpB,cAAc,OAAO,QAAQ,CAAC,UAAU,CACzC;IACD,MAAM,SAAS,IAAI,SAAS,QAAQ,QAAQ,UAC1C,KAAK,UAAU,qBAAqB,SAAS,CAAC,CAC/C;AAED,SAAK,MAAM,YAAY,KAAK,QAAQ,UAClC,KAAI,YAAY,SAAS,SAAS,CAChC,aAAY,YAAY,UAAU,OAAO;QAEzC,aAAY,UAAU,UAAU,OAAO;KAI9C;IAEJ"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { getManifestFileName, simpleJoinRemoteEntry } from "@module-federation/sdk";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/NextFederationPlugin/FederatedStatsCompatibilityPlugin.ts
|
|
4
|
+
const createFederatedStats = (manifest) => {
|
|
5
|
+
const exposes = {};
|
|
6
|
+
for (const expose of manifest.exposes) exposes[expose.path || `./${expose.name}`] = [...expose.assets.js.sync, ...expose.assets.css.sync];
|
|
7
|
+
return {
|
|
8
|
+
sharedModules: [],
|
|
9
|
+
federatedModules: [{
|
|
10
|
+
remote: manifest.name,
|
|
11
|
+
entry: simpleJoinRemoteEntry(manifest.metaData.remoteEntry.path, manifest.metaData.remoteEntry.name),
|
|
12
|
+
sharedModules: [],
|
|
13
|
+
exposes,
|
|
14
|
+
remoteModules: {}
|
|
15
|
+
}]
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
var FederatedStatsCompatibilityPlugin = class {
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.options = options;
|
|
21
|
+
}
|
|
22
|
+
apply(compiler) {
|
|
23
|
+
compiler.hooks.thisCompilation.tap("FederatedStatsCompatibilityPlugin", (compilation) => {
|
|
24
|
+
compilation.hooks.processAssets.tap({
|
|
25
|
+
name: "FederatedStatsCompatibilityPlugin",
|
|
26
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT
|
|
27
|
+
}, () => {
|
|
28
|
+
const manifestFilename = getManifestFileName(this.options.manifest).manifestFileName;
|
|
29
|
+
const manifestAsset = compilation.getAsset(manifestFilename);
|
|
30
|
+
if (!manifestAsset) throw new Error(`Cannot emit federated-stats.json because ${manifestFilename} was not generated`);
|
|
31
|
+
const manifest = JSON.parse(manifestAsset.source.source().toString());
|
|
32
|
+
const source = new compiler.webpack.sources.RawSource(JSON.stringify(createFederatedStats(manifest)));
|
|
33
|
+
for (const filename of this.options.filenames) if (compilation.getAsset(filename)) compilation.updateAsset(filename, source);
|
|
34
|
+
else compilation.emitAsset(filename, source);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { FederatedStatsCompatibilityPlugin };
|
|
42
|
+
//# sourceMappingURL=FederatedStatsCompatibilityPlugin.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FederatedStatsCompatibilityPlugin.mjs","names":[],"sources":["../../../../src/plugins/NextFederationPlugin/FederatedStatsCompatibilityPlugin.ts"],"sourcesContent":["import type { Compiler, WebpackPluginInstance } from 'webpack';\nimport {\n getManifestFileName,\n simpleJoinRemoteEntry,\n type Manifest,\n type moduleFederationPlugin,\n} from '@module-federation/sdk';\n\ntype FederatedStatsCompatibilityPluginOptions = {\n filenames: string[];\n manifest: moduleFederationPlugin.ModuleFederationPluginOptions['manifest'];\n};\n\nexport const createFederatedStats = (manifest: Manifest) => {\n const exposes: Record<string, string[]> = {};\n\n for (const expose of manifest.exposes) {\n exposes[expose.path || `./${expose.name}`] = [\n ...expose.assets.js.sync,\n ...expose.assets.css.sync,\n ];\n }\n\n return {\n sharedModules: [],\n federatedModules: [\n {\n remote: manifest.name,\n entry: simpleJoinRemoteEntry(\n manifest.metaData.remoteEntry.path,\n manifest.metaData.remoteEntry.name,\n ),\n sharedModules: [],\n exposes,\n remoteModules: {},\n },\n ],\n };\n};\n\nexport class FederatedStatsCompatibilityPlugin implements WebpackPluginInstance {\n private readonly options: FederatedStatsCompatibilityPluginOptions;\n\n constructor(options: FederatedStatsCompatibilityPluginOptions) {\n this.options = options;\n }\n\n apply(compiler: Compiler): void {\n compiler.hooks.thisCompilation.tap(\n 'FederatedStatsCompatibilityPlugin',\n (compilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: 'FederatedStatsCompatibilityPlugin',\n stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT,\n },\n () => {\n const manifestFilename = getManifestFileName(\n this.options.manifest,\n ).manifestFileName;\n const manifestAsset = compilation.getAsset(manifestFilename);\n if (!manifestAsset) {\n throw new Error(\n `Cannot emit federated-stats.json because ${manifestFilename} was not generated`,\n );\n }\n\n const manifest = JSON.parse(\n manifestAsset.source.source().toString(),\n ) as Manifest;\n const source = new compiler.webpack.sources.RawSource(\n JSON.stringify(createFederatedStats(manifest)),\n );\n\n for (const filename of this.options.filenames) {\n if (compilation.getAsset(filename)) {\n compilation.updateAsset(filename, source);\n } else {\n compilation.emitAsset(filename, source);\n }\n }\n },\n );\n },\n );\n }\n}\n"],"mappings":";;;AAaA,MAAa,wBAAwB,aAAuB;CAC1D,MAAM,UAAoC,EAAE;AAE5C,MAAK,MAAM,UAAU,SAAS,QAC5B,SAAQ,OAAO,QAAQ,KAAK,OAAO,UAAU,CAC3C,GAAG,OAAO,OAAO,GAAG,MACpB,GAAG,OAAO,OAAO,IAAI,KACtB;AAGH,QAAO;EACL,eAAe,EAAE;EACjB,kBAAkB,CAChB;GACE,QAAQ,SAAS;GACjB,OAAO,sBACL,SAAS,SAAS,YAAY,MAC9B,SAAS,SAAS,YAAY,KAC/B;GACD,eAAe,EAAE;GACjB;GACA,eAAe,EAAE;GAClB,CACF;EACF;;AAGH,IAAa,oCAAb,MAAgF;CAG9E,YAAY,SAAmD;AAC7D,OAAK,UAAU;;CAGjB,MAAM,UAA0B;AAC9B,WAAS,MAAM,gBAAgB,IAC7B,sCACC,gBAAgB;AACf,eAAY,MAAM,cAAc,IAC9B;IACE,MAAM;IACN,OAAO,SAAS,QAAQ,YAAY;IACrC,QACK;IACJ,MAAM,mBAAmB,oBACvB,KAAK,QAAQ,SACd,CAAC;IACF,MAAM,gBAAgB,YAAY,SAAS,iBAAiB;AAC5D,QAAI,CAAC,cACH,OAAM,IAAI,MACR,4CAA4C,iBAAiB,oBAC9D;IAGH,MAAM,WAAW,KAAK,MACpB,cAAc,OAAO,QAAQ,CAAC,UAAU,CACzC;IACD,MAAM,SAAS,IAAI,SAAS,QAAQ,QAAQ,UAC1C,KAAK,UAAU,qBAAqB,SAAS,CAAC,CAC/C;AAED,SAAK,MAAM,YAAY,KAAK,QAAQ,UAClC,KAAI,YAAY,SAAS,SAAS,CAChC,aAAY,YAAY,UAAU,OAAO;QAEzC,aAAY,UAAU,UAAU,OAAO;KAI9C;IAEJ"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
const require_runtime = require('../../../_virtual/_rolldown/runtime.js');
|
|
2
2
|
const require_logger = require('../../logger.js');
|
|
3
3
|
const require_InvertedContainerPlugin = require('../container/InvertedContainerPlugin.js');
|
|
4
|
+
const require_FederatedStatsCompatibilityPlugin = require('./FederatedStatsCompatibilityPlugin.js');
|
|
4
5
|
let _module_federation_node = require("@module-federation/node");
|
|
5
6
|
|
|
6
7
|
//#region src/plugins/NextFederationPlugin/apply-client-plugins.ts
|
|
8
|
+
const FEDERATED_STATS_FILENAMES = ["static/chunks/federated-stats.json", "server/federated-stats.json"];
|
|
7
9
|
/**
|
|
8
10
|
* Applies client-specific plugins.
|
|
9
11
|
*
|
|
@@ -32,7 +34,11 @@ function applyClientPlugins(compiler, options, extraOptions) {
|
|
|
32
34
|
type: "window",
|
|
33
35
|
name
|
|
34
36
|
};
|
|
35
|
-
new _module_federation_node.ChunkCorrelationPlugin({ filename:
|
|
37
|
+
if (!(options.manifest !== false && (typeof options.manifest !== "object" || !options.manifest.disableAssetsAnalyze))) new _module_federation_node.ChunkCorrelationPlugin({ filename: FEDERATED_STATS_FILENAMES }).apply(compiler);
|
|
38
|
+
else new require_FederatedStatsCompatibilityPlugin.FederatedStatsCompatibilityPlugin({
|
|
39
|
+
filenames: FEDERATED_STATS_FILENAMES,
|
|
40
|
+
manifest: options.manifest
|
|
41
|
+
}).apply(compiler);
|
|
36
42
|
new require_InvertedContainerPlugin.default().apply(compiler);
|
|
37
43
|
}
|
|
38
44
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-client-plugins.js","names":["ChunkCorrelationPlugin","InvertedContainerPlugin"],"sources":["../../../../src/plugins/NextFederationPlugin/apply-client-plugins.ts"],"sourcesContent":["import type { Compiler } from 'webpack';\nimport { ChunkCorrelationPlugin } from '@module-federation/node';\nimport InvertedContainerPlugin from '../container/InvertedContainerPlugin';\nimport type { moduleFederationPlugin } from '@module-federation/sdk';\nimport type { NextFederationPluginExtraOptions } from './next-fragments';\nimport logger from '../../logger';\n\n/**\n * Applies client-specific plugins.\n *\n * @param compiler - The Webpack compiler instance.\n * @param options - The ModuleFederationPluginOptions instance.\n * @param extraOptions - The NextFederationPluginExtraOptions instance.\n *\n * @remarks\n * This function applies plugins to the Webpack compiler instance that are specific to the client build of\n * a Next.js application with Module Federation enabled. These plugins include the following:\n *\n * - ChunkCorrelationPlugin: Collects metadata on chunks to enable proper module loading across different runtimes.\n * - InvertedContainerPlugin: Adds custom runtime modules to the container runtime to allow a host to expose its\n * own remote interface at startup.\n\n * If automatic page stitching is enabled, a warning is logged indicating that it is disabled in v7.\n * If a custom library is specified in the options, an error is logged. The options.library property is\n * also set to `{ type: 'window', name: options.name }`.\n */\nexport function applyClientPlugins(\n compiler: Compiler,\n options: moduleFederationPlugin.ModuleFederationPluginOptions,\n extraOptions: NextFederationPluginExtraOptions,\n): void {\n const { name } = options;\n\n // Adjust the public path if it is set to the default Next.js path\n if (compiler.options.output.publicPath === '/_next/') {\n compiler.options.output.publicPath = 'auto';\n }\n\n // Log a warning if automatic page stitching is enabled, as it is disabled in v7\n if (extraOptions.automaticPageStitching) {\n logger.warn('automatic page stitching is disabled in v7');\n }\n\n // Log an error if a custom library is set, as it is not allowed\n if (options.library) {\n logger.error('you cannot set custom library');\n }\n\n // Set the library option to be a window object with the name of the module federation plugin\n options.library = {\n type: 'window',\n name,\n };\n\n //
|
|
1
|
+
{"version":3,"file":"apply-client-plugins.js","names":["ChunkCorrelationPlugin","FederatedStatsCompatibilityPlugin","InvertedContainerPlugin"],"sources":["../../../../src/plugins/NextFederationPlugin/apply-client-plugins.ts"],"sourcesContent":["import type { Compiler } from 'webpack';\nimport { ChunkCorrelationPlugin } from '@module-federation/node';\nimport InvertedContainerPlugin from '../container/InvertedContainerPlugin';\nimport type { moduleFederationPlugin } from '@module-federation/sdk';\nimport type { NextFederationPluginExtraOptions } from './next-fragments';\nimport logger from '../../logger';\nimport { FederatedStatsCompatibilityPlugin } from './FederatedStatsCompatibilityPlugin';\n\nconst FEDERATED_STATS_FILENAMES = [\n 'static/chunks/federated-stats.json',\n 'server/federated-stats.json',\n];\n\n/**\n * Applies client-specific plugins.\n *\n * @param compiler - The Webpack compiler instance.\n * @param options - The ModuleFederationPluginOptions instance.\n * @param extraOptions - The NextFederationPluginExtraOptions instance.\n *\n * @remarks\n * This function applies plugins to the Webpack compiler instance that are specific to the client build of\n * a Next.js application with Module Federation enabled. These plugins include the following:\n *\n * - ChunkCorrelationPlugin: Collects metadata on chunks to enable proper module loading across different runtimes.\n * - InvertedContainerPlugin: Adds custom runtime modules to the container runtime to allow a host to expose its\n * own remote interface at startup.\n\n * If automatic page stitching is enabled, a warning is logged indicating that it is disabled in v7.\n * If a custom library is specified in the options, an error is logged. The options.library property is\n * also set to `{ type: 'window', name: options.name }`.\n */\nexport function applyClientPlugins(\n compiler: Compiler,\n options: moduleFederationPlugin.ModuleFederationPluginOptions,\n extraOptions: NextFederationPluginExtraOptions,\n): void {\n const { name } = options;\n\n // Adjust the public path if it is set to the default Next.js path\n if (compiler.options.output.publicPath === '/_next/') {\n compiler.options.output.publicPath = 'auto';\n }\n\n // Log a warning if automatic page stitching is enabled, as it is disabled in v7\n if (extraOptions.automaticPageStitching) {\n logger.warn('automatic page stitching is disabled in v7');\n }\n\n // Log an error if a custom library is set, as it is not allowed\n if (options.library) {\n logger.error('you cannot set custom library');\n }\n\n // Set the library option to be a window object with the name of the module federation plugin\n options.library = {\n type: 'window',\n name,\n };\n\n // Preserve the legacy asset for hosts that have not migrated to manifests.\n const manifestHasAssets =\n options.manifest !== false &&\n (typeof options.manifest !== 'object' ||\n !options.manifest.disableAssetsAnalyze);\n\n if (!manifestHasAssets) {\n new ChunkCorrelationPlugin({\n filename: FEDERATED_STATS_FILENAMES,\n }).apply(compiler);\n } else {\n new FederatedStatsCompatibilityPlugin({\n filenames: FEDERATED_STATS_FILENAMES,\n manifest: options.manifest,\n }).apply(compiler);\n }\n\n // Apply the InvertedContainerPlugin to add custom runtime modules to the container runtime\n new InvertedContainerPlugin().apply(compiler);\n}\n"],"mappings":";;;;;;;AAQA,MAAM,4BAA4B,CAChC,sCACA,8BACD;;;;;;;;;;;;;;;;;;;;AAqBD,SAAgB,mBACd,UACA,SACA,cACM;CACN,MAAM,EAAE,SAAS;AAGjB,KAAI,SAAS,QAAQ,OAAO,eAAe,UACzC,UAAS,QAAQ,OAAO,aAAa;AAIvC,KAAI,aAAa,uBACf,wBAAO,KAAK,6CAA6C;AAI3D,KAAI,QAAQ,QACV,wBAAO,MAAM,gCAAgC;AAI/C,SAAQ,UAAU;EAChB,MAAM;EACN;EACD;AAQD,KAAI,EAJF,QAAQ,aAAa,UACpB,OAAO,QAAQ,aAAa,YAC3B,CAAC,QAAQ,SAAS,uBAGpB,KAAIA,+CAAuB,EACzB,UAAU,2BACX,CAAC,CAAC,MAAM,SAAS;KAElB,KAAIC,4EAAkC;EACpC,WAAW;EACX,UAAU,QAAQ;EACnB,CAAC,CAAC,MAAM,SAAS;AAIpB,KAAIC,yCAAyB,CAAC,MAAM,SAAS"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import logger from "../../logger.mjs";
|
|
2
2
|
import InvertedContainerPlugin from "../container/InvertedContainerPlugin.mjs";
|
|
3
|
+
import { FederatedStatsCompatibilityPlugin } from "./FederatedStatsCompatibilityPlugin.mjs";
|
|
3
4
|
import { ChunkCorrelationPlugin } from "@module-federation/node";
|
|
4
5
|
|
|
5
6
|
//#region src/plugins/NextFederationPlugin/apply-client-plugins.ts
|
|
7
|
+
const FEDERATED_STATS_FILENAMES = ["static/chunks/federated-stats.json", "server/federated-stats.json"];
|
|
6
8
|
/**
|
|
7
9
|
* Applies client-specific plugins.
|
|
8
10
|
*
|
|
@@ -31,7 +33,11 @@ function applyClientPlugins(compiler, options, extraOptions) {
|
|
|
31
33
|
type: "window",
|
|
32
34
|
name
|
|
33
35
|
};
|
|
34
|
-
new ChunkCorrelationPlugin({ filename:
|
|
36
|
+
if (!(options.manifest !== false && (typeof options.manifest !== "object" || !options.manifest.disableAssetsAnalyze))) new ChunkCorrelationPlugin({ filename: FEDERATED_STATS_FILENAMES }).apply(compiler);
|
|
37
|
+
else new FederatedStatsCompatibilityPlugin({
|
|
38
|
+
filenames: FEDERATED_STATS_FILENAMES,
|
|
39
|
+
manifest: options.manifest
|
|
40
|
+
}).apply(compiler);
|
|
35
41
|
new InvertedContainerPlugin().apply(compiler);
|
|
36
42
|
}
|
|
37
43
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-client-plugins.mjs","names":[],"sources":["../../../../src/plugins/NextFederationPlugin/apply-client-plugins.ts"],"sourcesContent":["import type { Compiler } from 'webpack';\nimport { ChunkCorrelationPlugin } from '@module-federation/node';\nimport InvertedContainerPlugin from '../container/InvertedContainerPlugin';\nimport type { moduleFederationPlugin } from '@module-federation/sdk';\nimport type { NextFederationPluginExtraOptions } from './next-fragments';\nimport logger from '../../logger';\n\n/**\n * Applies client-specific plugins.\n *\n * @param compiler - The Webpack compiler instance.\n * @param options - The ModuleFederationPluginOptions instance.\n * @param extraOptions - The NextFederationPluginExtraOptions instance.\n *\n * @remarks\n * This function applies plugins to the Webpack compiler instance that are specific to the client build of\n * a Next.js application with Module Federation enabled. These plugins include the following:\n *\n * - ChunkCorrelationPlugin: Collects metadata on chunks to enable proper module loading across different runtimes.\n * - InvertedContainerPlugin: Adds custom runtime modules to the container runtime to allow a host to expose its\n * own remote interface at startup.\n\n * If automatic page stitching is enabled, a warning is logged indicating that it is disabled in v7.\n * If a custom library is specified in the options, an error is logged. The options.library property is\n * also set to `{ type: 'window', name: options.name }`.\n */\nexport function applyClientPlugins(\n compiler: Compiler,\n options: moduleFederationPlugin.ModuleFederationPluginOptions,\n extraOptions: NextFederationPluginExtraOptions,\n): void {\n const { name } = options;\n\n // Adjust the public path if it is set to the default Next.js path\n if (compiler.options.output.publicPath === '/_next/') {\n compiler.options.output.publicPath = 'auto';\n }\n\n // Log a warning if automatic page stitching is enabled, as it is disabled in v7\n if (extraOptions.automaticPageStitching) {\n logger.warn('automatic page stitching is disabled in v7');\n }\n\n // Log an error if a custom library is set, as it is not allowed\n if (options.library) {\n logger.error('you cannot set custom library');\n }\n\n // Set the library option to be a window object with the name of the module federation plugin\n options.library = {\n type: 'window',\n name,\n };\n\n //
|
|
1
|
+
{"version":3,"file":"apply-client-plugins.mjs","names":[],"sources":["../../../../src/plugins/NextFederationPlugin/apply-client-plugins.ts"],"sourcesContent":["import type { Compiler } from 'webpack';\nimport { ChunkCorrelationPlugin } from '@module-federation/node';\nimport InvertedContainerPlugin from '../container/InvertedContainerPlugin';\nimport type { moduleFederationPlugin } from '@module-federation/sdk';\nimport type { NextFederationPluginExtraOptions } from './next-fragments';\nimport logger from '../../logger';\nimport { FederatedStatsCompatibilityPlugin } from './FederatedStatsCompatibilityPlugin';\n\nconst FEDERATED_STATS_FILENAMES = [\n 'static/chunks/federated-stats.json',\n 'server/federated-stats.json',\n];\n\n/**\n * Applies client-specific plugins.\n *\n * @param compiler - The Webpack compiler instance.\n * @param options - The ModuleFederationPluginOptions instance.\n * @param extraOptions - The NextFederationPluginExtraOptions instance.\n *\n * @remarks\n * This function applies plugins to the Webpack compiler instance that are specific to the client build of\n * a Next.js application with Module Federation enabled. These plugins include the following:\n *\n * - ChunkCorrelationPlugin: Collects metadata on chunks to enable proper module loading across different runtimes.\n * - InvertedContainerPlugin: Adds custom runtime modules to the container runtime to allow a host to expose its\n * own remote interface at startup.\n\n * If automatic page stitching is enabled, a warning is logged indicating that it is disabled in v7.\n * If a custom library is specified in the options, an error is logged. The options.library property is\n * also set to `{ type: 'window', name: options.name }`.\n */\nexport function applyClientPlugins(\n compiler: Compiler,\n options: moduleFederationPlugin.ModuleFederationPluginOptions,\n extraOptions: NextFederationPluginExtraOptions,\n): void {\n const { name } = options;\n\n // Adjust the public path if it is set to the default Next.js path\n if (compiler.options.output.publicPath === '/_next/') {\n compiler.options.output.publicPath = 'auto';\n }\n\n // Log a warning if automatic page stitching is enabled, as it is disabled in v7\n if (extraOptions.automaticPageStitching) {\n logger.warn('automatic page stitching is disabled in v7');\n }\n\n // Log an error if a custom library is set, as it is not allowed\n if (options.library) {\n logger.error('you cannot set custom library');\n }\n\n // Set the library option to be a window object with the name of the module federation plugin\n options.library = {\n type: 'window',\n name,\n };\n\n // Preserve the legacy asset for hosts that have not migrated to manifests.\n const manifestHasAssets =\n options.manifest !== false &&\n (typeof options.manifest !== 'object' ||\n !options.manifest.disableAssetsAnalyze);\n\n if (!manifestHasAssets) {\n new ChunkCorrelationPlugin({\n filename: FEDERATED_STATS_FILENAMES,\n }).apply(compiler);\n } else {\n new FederatedStatsCompatibilityPlugin({\n filenames: FEDERATED_STATS_FILENAMES,\n manifest: options.manifest,\n }).apply(compiler);\n }\n\n // Apply the InvertedContainerPlugin to add custom runtime modules to the container runtime\n new InvertedContainerPlugin().apply(compiler);\n}\n"],"mappings":";;;;;;AAQA,MAAM,4BAA4B,CAChC,sCACA,8BACD;;;;;;;;;;;;;;;;;;;;AAqBD,SAAgB,mBACd,UACA,SACA,cACM;CACN,MAAM,EAAE,SAAS;AAGjB,KAAI,SAAS,QAAQ,OAAO,eAAe,UACzC,UAAS,QAAQ,OAAO,aAAa;AAIvC,KAAI,aAAa,uBACf,QAAO,KAAK,6CAA6C;AAI3D,KAAI,QAAQ,QACV,QAAO,MAAM,gCAAgC;AAI/C,SAAQ,UAAU;EAChB,MAAM;EACN;EACD;AAQD,KAAI,EAJF,QAAQ,aAAa,UACpB,OAAO,QAAQ,aAAa,YAC3B,CAAC,QAAQ,SAAS,uBAGpB,KAAI,uBAAuB,EACzB,UAAU,2BACX,CAAC,CAAC,MAAM,SAAS;KAElB,KAAI,kCAAkC;EACpC,WAAW;EACX,UAAU,QAAQ;EACnB,CAAC,CAAC,MAAM,SAAS;AAIpB,KAAI,yBAAyB,CAAC,MAAM,SAAS"}
|
|
@@ -9,6 +9,7 @@ const require_set_options = require('./set-options.js');
|
|
|
9
9
|
const require_validate_options = require('./validate-options.js');
|
|
10
10
|
const require_apply_server_plugins = require('./apply-server-plugins.js');
|
|
11
11
|
const require_apply_client_plugins = require('./apply-client-plugins.js');
|
|
12
|
+
const require_manifest_options = require('./manifest-options.js');
|
|
12
13
|
let path = require("path");
|
|
13
14
|
path = require_runtime.__toESM(path);
|
|
14
15
|
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
@@ -119,7 +120,6 @@ var NextFederationPlugin = class {
|
|
|
119
120
|
}
|
|
120
121
|
getNormalFederationPluginOptions(compiler, isServer) {
|
|
121
122
|
const defaultShared = this._extraOptions.skipSharingNextInternals ? {} : require_next_fragments.retrieveDefaultShared(isServer);
|
|
122
|
-
const manifestOptions = typeof this._options.manifest === "object" && this._options.manifest !== null ? this._options.manifest : {};
|
|
123
123
|
return {
|
|
124
124
|
...this._options,
|
|
125
125
|
runtime: false,
|
|
@@ -138,10 +138,7 @@ var NextFederationPlugin = class {
|
|
|
138
138
|
...defaultShared,
|
|
139
139
|
...this._options.shared
|
|
140
140
|
},
|
|
141
|
-
manifest:
|
|
142
|
-
...manifestOptions,
|
|
143
|
-
filePath: isServer ? "" : "/static/chunks"
|
|
144
|
-
},
|
|
141
|
+
manifest: require_manifest_options.normalizeManifestOptions(this._options.manifest, isServer),
|
|
145
142
|
dts: this._options.dts ?? false,
|
|
146
143
|
shareStrategy: this._options.shareStrategy ?? "loaded-first",
|
|
147
144
|
experiments: { asyncStartup: true }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["setOptions","logger","CopyFederationPlugin","ModuleFederationPlugin","validateCompilerOptions","validatePluginOptions","retrieveDefaultShared","exposeNextjsPages"],"sources":["../../../../src/plugins/NextFederationPlugin/index.ts"],"sourcesContent":["/**\n * MIT License http://www.opensource.org/licenses/mit-license.php\n * Author Zackary Jackson @ScriptedAlchemy\n * This module contains the NextFederationPlugin class which is a webpack plugin that handles Next.js application federation using Module Federation.\n */\n'use strict';\n\nimport type {\n NextFederationPluginExtraOptions,\n NextFederationPluginOptions,\n} from './next-fragments';\nimport type { Compiler, WebpackPluginInstance } from 'webpack';\nimport path from 'path';\nimport { getWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport CopyFederationPlugin from '../CopyFederationPlugin';\nimport { exposeNextjsPages } from '../../loaders/nextPageMapLoader';\nimport { retrieveDefaultShared, applyPathFixes } from './next-fragments';\nimport { setOptions } from './set-options';\nimport {\n validateCompilerOptions,\n validatePluginOptions,\n} from './validate-options';\nimport {\n applyServerPlugins,\n configureServerCompilerOptions,\n configureServerLibraryAndFilename,\n handleServerExternals,\n} from './apply-server-plugins';\nimport { applyClientPlugins } from './apply-client-plugins';\nimport { ModuleFederationPlugin } from '@module-federation/enhanced/webpack';\nimport { bindLoggerToCompiler } from '@module-federation/sdk';\nimport type { moduleFederationPlugin } from '@module-federation/sdk';\nimport logger from '../../logger';\n\nconst resolveRuntimePluginPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js');\n\nconst resolveNoopPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.js');\n\nconst resolveNodeRuntimePluginPath = (): string => {\n const nodePackageRoot = path.dirname(\n require.resolve('@module-federation/node/package.json'),\n );\n\n return require.resolve(\n path.join(\n nodePackageRoot,\n process.env.IS_ESM_BUILD === 'true'\n ? 'dist/src/runtimePlugin.mjs'\n : 'dist/src/runtimePlugin.js',\n ),\n );\n};\n/**\n * NextFederationPlugin is a webpack plugin that handles Next.js application federation using Module Federation.\n */\nexport class NextFederationPlugin {\n private _options: moduleFederationPlugin.ModuleFederationPluginOptions;\n private _extraOptions: NextFederationPluginExtraOptions;\n public name: string;\n /**\n * Constructs the NextFederationPlugin with the provided options.\n *\n * @param options The options to configure the plugin.\n */\n constructor(options: NextFederationPluginOptions) {\n const { mainOptions, extraOptions } = setOptions(options);\n this._options = mainOptions;\n this._extraOptions = extraOptions;\n this.name = 'ModuleFederationPlugin';\n }\n\n /**\n * The apply method is called by the webpack compiler and allows the plugin to hook into the webpack process.\n * @param compiler The webpack compiler object.\n */\n apply(compiler: Compiler) {\n bindLoggerToCompiler(logger, compiler, 'NextFederationPlugin');\n process.env['FEDERATION_WEBPACK_PATH'] =\n process.env['FEDERATION_WEBPACK_PATH'] ||\n getWebpackPath(compiler, { framework: 'nextjs' });\n if (!this.validateOptions(compiler)) return;\n const isServer = this.isServerCompiler(compiler);\n new CopyFederationPlugin(isServer).apply(compiler);\n const normalFederationPluginOptions = this.getNormalFederationPluginOptions(\n compiler,\n isServer,\n );\n this._options = normalFederationPluginOptions;\n this.applyConditionalPlugins(compiler, isServer);\n\n new ModuleFederationPlugin(normalFederationPluginOptions).apply(compiler);\n\n const noop = this.getNoopPath();\n\n if (!this._extraOptions.skipSharingNextInternals) {\n compiler.hooks.make.tapAsync(\n 'NextFederationPlugin',\n (compilation, callback) => {\n const dep = compiler.webpack.EntryPlugin.createDependency(\n noop,\n 'noop',\n );\n compilation.addEntry(\n compiler.context,\n dep,\n { name: 'noop' },\n (err, module) => {\n if (err) {\n return callback(err);\n }\n callback();\n },\n );\n },\n );\n }\n\n if (!compiler.options.ignoreWarnings) {\n compiler.options.ignoreWarnings = [\n //@ts-ignore\n (message) => /your target environment does not appear/.test(message),\n ];\n }\n }\n\n private validateOptions(compiler: Compiler): boolean {\n const manifestPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance =>\n p?.constructor?.name === 'BuildManifestPlugin',\n );\n\n if (manifestPlugin) {\n //@ts-ignore\n if (manifestPlugin?.appDirEnabled) {\n throw new Error(\n 'App Directory is not supported by nextjs-mf. Use only pages directory, do not open git issues about this',\n );\n }\n }\n\n const compilerValid = validateCompilerOptions(compiler);\n const pluginValid = validatePluginOptions(this._options);\n const envValid = process.env['NEXT_PRIVATE_LOCAL_WEBPACK'];\n if (compilerValid === undefined) logger.error('Compiler validation failed');\n if (pluginValid === undefined) logger.error('Plugin validation failed');\n const validCompilerTarget =\n compiler.options.name === 'server' || compiler.options.name === 'client';\n if (!envValid)\n throw new Error(\n 'process.env.NEXT_PRIVATE_LOCAL_WEBPACK is not set to true, please set it to true, and \"npm install webpack\"',\n );\n return (\n compilerValid !== undefined &&\n pluginValid !== undefined &&\n validCompilerTarget\n );\n }\n\n private isServerCompiler(compiler: Compiler): boolean {\n return compiler.options.name === 'server';\n }\n\n private applyConditionalPlugins(compiler: Compiler, isServer: boolean) {\n compiler.options.output.uniqueName = this._options.name;\n compiler.options.output.environment = {\n ...compiler.options.output.environment,\n asyncFunction: true,\n };\n\n // Add layer rules for resource queries\n if (!compiler.options.module.rules) {\n compiler.options.module.rules = [];\n }\n\n // Add layer rules for RSC, client and SSR\n compiler.options.module.rules.push({\n resourceQuery: /\\?rsc/,\n layer: 'rsc',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?client/,\n layer: 'client',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?ssr/,\n layer: 'ssr',\n });\n\n applyPathFixes(compiler, this._options, this._extraOptions);\n if (this._extraOptions.debug) {\n compiler.options.devtool = false;\n }\n\n if (isServer) {\n configureServerCompilerOptions(compiler);\n configureServerLibraryAndFilename(this._options);\n applyServerPlugins(compiler, this._options);\n handleServerExternals(compiler, {\n ...this._options,\n shared: { ...retrieveDefaultShared(isServer), ...this._options.shared },\n });\n } else {\n applyClientPlugins(compiler, this._options, this._extraOptions);\n }\n }\n\n private getNormalFederationPluginOptions(\n compiler: Compiler,\n isServer: boolean,\n ): moduleFederationPlugin.ModuleFederationPluginOptions {\n const defaultShared = this._extraOptions.skipSharingNextInternals\n ? {}\n : retrieveDefaultShared(isServer);\n const manifestOptions =\n typeof this._options.manifest === 'object' &&\n this._options.manifest !== null\n ? this._options.manifest\n : {};\n\n return {\n ...this._options,\n runtime: false,\n remoteType: 'script',\n runtimePlugins: [\n ...(isServer ? [resolveNodeRuntimePluginPath()] : []),\n resolveRuntimePluginPath(),\n ...(this._options.runtimePlugins || []),\n ].map((plugin) => plugin + '?runtimePlugin'),\n //@ts-ignore\n exposes: {\n ...this._options.exposes,\n ...(this._extraOptions.exposePages\n ? exposeNextjsPages(compiler.options.context as string)\n : {}),\n },\n remotes: {\n ...this._options.remotes,\n },\n shared: {\n ...defaultShared,\n ...(this._options.shared as Record<string, unknown>),\n },\n manifest: {\n ...manifestOptions,\n filePath: isServer ? '' : '/static/chunks',\n },\n // nextjs project needs to add config.watchOptions = ['**/node_modules/**', '**/@mf-types/**'] to prevent loop types update\n dts: this._options.dts ?? false,\n shareStrategy: this._options.shareStrategy ?? 'loaded-first',\n experiments: {\n asyncStartup: true,\n },\n };\n }\n\n private getNoopPath(): string {\n return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AS;AAChD,mDAAmB,UAAU,KAAK,SAAS;AAC3C,sDAAsB,UAAU;IAC9B,GAAG,KAAK;IACR,QAAQ;KAAE,GAAGC,6CAAsB,SAAS;KAAE,GAAG,KAAK,SAAS;KAAQ;IACxE,CAAC;QAEF,iDAAmB,UAAU,KAAK,UAAU,KAAK,cAAc;;CAInE,AAAQ,iCACN,UACA,UACsD;EACtD,MAAM,gBAAgB,KAAK,cAAc,2BACrC,EAAE,GACFA,6CAAsB,SAAS;EACnC,MAAM,kBACJ,OAAO,KAAK,SAAS,aAAa,YAClC,KAAK,SAAS,aAAa,OACvB,KAAK,SAAS,WACd,EAAE;AAER,SAAO;GACL,GAAG,KAAK;GACR,SAAS;GACT,YAAY;GACZ,gBAAgB;IACd,GAAI,WAAW,CAAC,8BAA8B,CAAC,GAAG,EAAE;IACpD,0BAA0B;IAC1B,GAAI,KAAK,SAAS,kBAAkB,EAAE;IACvC,CAAC,KAAK,WAAW,SAAS,iBAAiB;GAE5C,SAAS;IACP,GAAG,KAAK,SAAS;IACjB,GAAI,KAAK,cAAc,cACnBC,wDAAkB,SAAS,QAAQ,QAAkB,GACrD,EAAE;IACP;GACD,SAAS,EACP,GAAG,KAAK,SAAS,SAClB;GACD,QAAQ;IACN,GAAG;IACH,GAAI,KAAK,SAAS;IACnB;GACD,UAAU;IACR,GAAG;IACH,UAAU,WAAW,KAAK;IAC3B;GAED,KAAK,KAAK,SAAS,OAAO;GAC1B,eAAe,KAAK,SAAS,iBAAiB;GAC9C,aAAa,EACX,cAAc,MACf;GACF;;CAGH,AAAQ,cAAsB;AAC5B,SAAO,iBAAiB"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["setOptions","logger","CopyFederationPlugin","ModuleFederationPlugin","validateCompilerOptions","validatePluginOptions","retrieveDefaultShared","exposeNextjsPages","normalizeManifestOptions"],"sources":["../../../../src/plugins/NextFederationPlugin/index.ts"],"sourcesContent":["/**\n * MIT License http://www.opensource.org/licenses/mit-license.php\n * Author Zackary Jackson @ScriptedAlchemy\n * This module contains the NextFederationPlugin class which is a webpack plugin that handles Next.js application federation using Module Federation.\n */\n'use strict';\n\nimport type {\n NextFederationPluginExtraOptions,\n NextFederationPluginOptions,\n} from './next-fragments';\nimport type { Compiler, WebpackPluginInstance } from 'webpack';\nimport path from 'path';\nimport { getWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport CopyFederationPlugin from '../CopyFederationPlugin';\nimport { exposeNextjsPages } from '../../loaders/nextPageMapLoader';\nimport { retrieveDefaultShared, applyPathFixes } from './next-fragments';\nimport { setOptions } from './set-options';\nimport {\n validateCompilerOptions,\n validatePluginOptions,\n} from './validate-options';\nimport {\n applyServerPlugins,\n configureServerCompilerOptions,\n configureServerLibraryAndFilename,\n handleServerExternals,\n} from './apply-server-plugins';\nimport { applyClientPlugins } from './apply-client-plugins';\nimport { ModuleFederationPlugin } from '@module-federation/enhanced/webpack';\nimport { bindLoggerToCompiler } from '@module-federation/sdk';\nimport type { moduleFederationPlugin } from '@module-federation/sdk';\nimport logger from '../../logger';\nimport { normalizeManifestOptions } from './manifest-options';\n\nconst resolveRuntimePluginPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js');\n\nconst resolveNoopPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.js');\n\nconst resolveNodeRuntimePluginPath = (): string => {\n const nodePackageRoot = path.dirname(\n require.resolve('@module-federation/node/package.json'),\n );\n\n return require.resolve(\n path.join(\n nodePackageRoot,\n process.env.IS_ESM_BUILD === 'true'\n ? 'dist/src/runtimePlugin.mjs'\n : 'dist/src/runtimePlugin.js',\n ),\n );\n};\n/**\n * NextFederationPlugin is a webpack plugin that handles Next.js application federation using Module Federation.\n */\nexport class NextFederationPlugin {\n private _options: moduleFederationPlugin.ModuleFederationPluginOptions;\n private _extraOptions: NextFederationPluginExtraOptions;\n public name: string;\n /**\n * Constructs the NextFederationPlugin with the provided options.\n *\n * @param options The options to configure the plugin.\n */\n constructor(options: NextFederationPluginOptions) {\n const { mainOptions, extraOptions } = setOptions(options);\n this._options = mainOptions;\n this._extraOptions = extraOptions;\n this.name = 'ModuleFederationPlugin';\n }\n\n /**\n * The apply method is called by the webpack compiler and allows the plugin to hook into the webpack process.\n * @param compiler The webpack compiler object.\n */\n apply(compiler: Compiler) {\n bindLoggerToCompiler(logger, compiler, 'NextFederationPlugin');\n process.env['FEDERATION_WEBPACK_PATH'] =\n process.env['FEDERATION_WEBPACK_PATH'] ||\n getWebpackPath(compiler, { framework: 'nextjs' });\n if (!this.validateOptions(compiler)) return;\n const isServer = this.isServerCompiler(compiler);\n new CopyFederationPlugin(isServer).apply(compiler);\n const normalFederationPluginOptions = this.getNormalFederationPluginOptions(\n compiler,\n isServer,\n );\n this._options = normalFederationPluginOptions;\n this.applyConditionalPlugins(compiler, isServer);\n\n new ModuleFederationPlugin(normalFederationPluginOptions).apply(compiler);\n\n const noop = this.getNoopPath();\n\n if (!this._extraOptions.skipSharingNextInternals) {\n compiler.hooks.make.tapAsync(\n 'NextFederationPlugin',\n (compilation, callback) => {\n const dep = compiler.webpack.EntryPlugin.createDependency(\n noop,\n 'noop',\n );\n compilation.addEntry(\n compiler.context,\n dep,\n { name: 'noop' },\n (err, module) => {\n if (err) {\n return callback(err);\n }\n callback();\n },\n );\n },\n );\n }\n\n if (!compiler.options.ignoreWarnings) {\n compiler.options.ignoreWarnings = [\n //@ts-ignore\n (message) => /your target environment does not appear/.test(message),\n ];\n }\n }\n\n private validateOptions(compiler: Compiler): boolean {\n const manifestPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance =>\n p?.constructor?.name === 'BuildManifestPlugin',\n );\n\n if (manifestPlugin) {\n //@ts-ignore\n if (manifestPlugin?.appDirEnabled) {\n throw new Error(\n 'App Directory is not supported by nextjs-mf. Use only pages directory, do not open git issues about this',\n );\n }\n }\n\n const compilerValid = validateCompilerOptions(compiler);\n const pluginValid = validatePluginOptions(this._options);\n const envValid = process.env['NEXT_PRIVATE_LOCAL_WEBPACK'];\n if (compilerValid === undefined) logger.error('Compiler validation failed');\n if (pluginValid === undefined) logger.error('Plugin validation failed');\n const validCompilerTarget =\n compiler.options.name === 'server' || compiler.options.name === 'client';\n if (!envValid)\n throw new Error(\n 'process.env.NEXT_PRIVATE_LOCAL_WEBPACK is not set to true, please set it to true, and \"npm install webpack\"',\n );\n return (\n compilerValid !== undefined &&\n pluginValid !== undefined &&\n validCompilerTarget\n );\n }\n\n private isServerCompiler(compiler: Compiler): boolean {\n return compiler.options.name === 'server';\n }\n\n private applyConditionalPlugins(compiler: Compiler, isServer: boolean) {\n compiler.options.output.uniqueName = this._options.name;\n compiler.options.output.environment = {\n ...compiler.options.output.environment,\n asyncFunction: true,\n };\n\n // Add layer rules for resource queries\n if (!compiler.options.module.rules) {\n compiler.options.module.rules = [];\n }\n\n // Add layer rules for RSC, client and SSR\n compiler.options.module.rules.push({\n resourceQuery: /\\?rsc/,\n layer: 'rsc',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?client/,\n layer: 'client',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?ssr/,\n layer: 'ssr',\n });\n\n applyPathFixes(compiler, this._options, this._extraOptions);\n if (this._extraOptions.debug) {\n compiler.options.devtool = false;\n }\n\n if (isServer) {\n configureServerCompilerOptions(compiler);\n configureServerLibraryAndFilename(this._options);\n applyServerPlugins(compiler, this._options);\n handleServerExternals(compiler, {\n ...this._options,\n shared: { ...retrieveDefaultShared(isServer), ...this._options.shared },\n });\n } else {\n applyClientPlugins(compiler, this._options, this._extraOptions);\n }\n }\n\n private getNormalFederationPluginOptions(\n compiler: Compiler,\n isServer: boolean,\n ): moduleFederationPlugin.ModuleFederationPluginOptions {\n const defaultShared = this._extraOptions.skipSharingNextInternals\n ? {}\n : retrieveDefaultShared(isServer);\n return {\n ...this._options,\n runtime: false,\n remoteType: 'script',\n runtimePlugins: [\n ...(isServer ? [resolveNodeRuntimePluginPath()] : []),\n resolveRuntimePluginPath(),\n ...(this._options.runtimePlugins || []),\n ].map((plugin) => plugin + '?runtimePlugin'),\n //@ts-ignore\n exposes: {\n ...this._options.exposes,\n ...(this._extraOptions.exposePages\n ? exposeNextjsPages(compiler.options.context as string)\n : {}),\n },\n remotes: {\n ...this._options.remotes,\n },\n shared: {\n ...defaultShared,\n ...(this._options.shared as Record<string, unknown>),\n },\n manifest: normalizeManifestOptions(this._options.manifest, isServer),\n // nextjs project needs to add config.watchOptions = ['**/node_modules/**', '**/@mf-types/**'] to prevent loop types update\n dts: this._options.dts ?? false,\n shareStrategy: this._options.shareStrategy ?? 'loaded-first',\n experiments: {\n asyncStartup: true,\n },\n };\n }\n\n private getNoopPath(): string {\n return resolveNoopPath();\n }\n}\n\nexport default NextFederationPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,iCAGA,QAAQ,QAAQ,2EAA2E;AAEjG,MAAM,wBAGA,QAAQ,QAAQ,2DAA2D;AAEjF,MAAM,qCAA6C;CACjD,MAAM,kBAAkB,aAAK,QAC3B,QAAQ,QAAQ,uCAAuC,CACxD;AAED,QAAO,QAAQ,QACb,aAAK,KACH,iBAGI,4BACL,CACF;;;;;AAKH,IAAa,uBAAb,MAAkC;;;;;;CAShC,YAAY,SAAsC;EAChD,MAAM,EAAE,aAAa,iBAAiBA,+BAAW,QAAQ;AACzD,OAAK,WAAW;AAChB,OAAK,gBAAgB;AACrB,OAAK,OAAO;;;;;;CAOd,MAAM,UAAoB;AACxB,mDAAqBC,wBAAQ,UAAU,uBAAuB;AAC9D,UAAQ,IAAI,6BACV,QAAQ,IAAI,gGACG,UAAU,EAAE,WAAW,UAAU,CAAC;AACnD,MAAI,CAAC,KAAK,gBAAg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S,EACP,GAAG,KAAK,SAAS,SAClB;GACD,QAAQ;IACN,GAAG;IACH,GAAI,KAAK,SAAS;IACnB;GACD,UAAUC,kDAAyB,KAAK,SAAS,UAAU,SAAS;GAEpE,KAAK,KAAK,SAAS,OAAO;GAC1B,eAAe,KAAK,SAAS,iBAAiB;GAC9C,aAAa,EACX,cAAc,MACf;GACF;;CAGH,AAAQ,cAAsB;AAC5B,SAAO,iBAAiB"}
|
|
@@ -7,6 +7,7 @@ import { setOptions } from "./set-options.mjs";
|
|
|
7
7
|
import { validateCompilerOptions, validatePluginOptions } from "./validate-options.mjs";
|
|
8
8
|
import { applyServerPlugins, configureServerCompilerOptions, configureServerLibraryAndFilename, handleServerExternals } from "./apply-server-plugins.mjs";
|
|
9
9
|
import { applyClientPlugins } from "./apply-client-plugins.mjs";
|
|
10
|
+
import { normalizeManifestOptions } from "./manifest-options.mjs";
|
|
10
11
|
import path from "path";
|
|
11
12
|
import { getWebpackPath } from "@module-federation/sdk/normalize-webpack-path";
|
|
12
13
|
import { bindLoggerToCompiler } from "@module-federation/sdk";
|
|
@@ -116,7 +117,6 @@ var NextFederationPlugin = class {
|
|
|
116
117
|
}
|
|
117
118
|
getNormalFederationPluginOptions(compiler, isServer) {
|
|
118
119
|
const defaultShared = this._extraOptions.skipSharingNextInternals ? {} : retrieveDefaultShared(isServer);
|
|
119
|
-
const manifestOptions = typeof this._options.manifest === "object" && this._options.manifest !== null ? this._options.manifest : {};
|
|
120
120
|
return {
|
|
121
121
|
...this._options,
|
|
122
122
|
runtime: false,
|
|
@@ -135,10 +135,7 @@ var NextFederationPlugin = class {
|
|
|
135
135
|
...defaultShared,
|
|
136
136
|
...this._options.shared
|
|
137
137
|
},
|
|
138
|
-
manifest:
|
|
139
|
-
...manifestOptions,
|
|
140
|
-
filePath: isServer ? "" : "/static/chunks"
|
|
141
|
-
},
|
|
138
|
+
manifest: normalizeManifestOptions(this._options.manifest, isServer),
|
|
142
139
|
dts: this._options.dts ?? false,
|
|
143
140
|
shareStrategy: this._options.shareStrategy ?? "loaded-first",
|
|
144
141
|
experiments: { asyncStartup: true }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["CopyFederationPlugin"],"sources":["../../../../src/plugins/NextFederationPlugin/index.ts"],"sourcesContent":["/**\n * MIT License http://www.opensource.org/licenses/mit-license.php\n * Author Zackary Jackson @ScriptedAlchemy\n * This module contains the NextFederationPlugin class which is a webpack plugin that handles Next.js application federation using Module Federation.\n */\n'use strict';\n\nimport type {\n NextFederationPluginExtraOptions,\n NextFederationPluginOptions,\n} from './next-fragments';\nimport type { Compiler, WebpackPluginInstance } from 'webpack';\nimport path from 'path';\nimport { getWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport CopyFederationPlugin from '../CopyFederationPlugin';\nimport { exposeNextjsPages } from '../../loaders/nextPageMapLoader';\nimport { retrieveDefaultShared, applyPathFixes } from './next-fragments';\nimport { setOptions } from './set-options';\nimport {\n validateCompilerOptions,\n validatePluginOptions,\n} from './validate-options';\nimport {\n applyServerPlugins,\n configureServerCompilerOptions,\n configureServerLibraryAndFilename,\n handleServerExternals,\n} from './apply-server-plugins';\nimport { applyClientPlugins } from './apply-client-plugins';\nimport { ModuleFederationPlugin } from '@module-federation/enhanced/webpack';\nimport { bindLoggerToCompiler } from '@module-federation/sdk';\nimport type { moduleFederationPlugin } from '@module-federation/sdk';\nimport logger from '../../logger';\n\nconst resolveRuntimePluginPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js');\n\nconst resolveNoopPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.js');\n\nconst resolveNodeRuntimePluginPath = (): string => {\n const nodePackageRoot = path.dirname(\n require.resolve('@module-federation/node/package.json'),\n );\n\n return require.resolve(\n path.join(\n nodePackageRoot,\n process.env.IS_ESM_BUILD === 'true'\n ? 'dist/src/runtimePlugin.mjs'\n : 'dist/src/runtimePlugin.js',\n ),\n );\n};\n/**\n * NextFederationPlugin is a webpack plugin that handles Next.js application federation using Module Federation.\n */\nexport class NextFederationPlugin {\n private _options: moduleFederationPlugin.ModuleFederationPluginOptions;\n private _extraOptions: NextFederationPluginExtraOptions;\n public name: string;\n /**\n * Constructs the NextFederationPlugin with the provided options.\n *\n * @param options The options to configure the plugin.\n */\n constructor(options: NextFederationPluginOptions) {\n const { mainOptions, extraOptions } = setOptions(options);\n this._options = mainOptions;\n this._extraOptions = extraOptions;\n this.name = 'ModuleFederationPlugin';\n }\n\n /**\n * The apply method is called by the webpack compiler and allows the plugin to hook into the webpack process.\n * @param compiler The webpack compiler object.\n */\n apply(compiler: Compiler) {\n bindLoggerToCompiler(logger, compiler, 'NextFederationPlugin');\n process.env['FEDERATION_WEBPACK_PATH'] =\n process.env['FEDERATION_WEBPACK_PATH'] ||\n getWebpackPath(compiler, { framework: 'nextjs' });\n if (!this.validateOptions(compiler)) return;\n const isServer = this.isServerCompiler(compiler);\n new CopyFederationPlugin(isServer).apply(compiler);\n const normalFederationPluginOptions = this.getNormalFederationPluginOptions(\n compiler,\n isServer,\n );\n this._options = normalFederationPluginOptions;\n this.applyConditionalPlugins(compiler, isServer);\n\n new ModuleFederationPlugin(normalFederationPluginOptions).apply(compiler);\n\n const noop = this.getNoopPath();\n\n if (!this._extraOptions.skipSharingNextInternals) {\n compiler.hooks.make.tapAsync(\n 'NextFederationPlugin',\n (compilation, callback) => {\n const dep = compiler.webpack.EntryPlugin.createDependency(\n noop,\n 'noop',\n );\n compilation.addEntry(\n compiler.context,\n dep,\n { name: 'noop' },\n (err, module) => {\n if (err) {\n return callback(err);\n }\n callback();\n },\n );\n },\n );\n }\n\n if (!compiler.options.ignoreWarnings) {\n compiler.options.ignoreWarnings = [\n //@ts-ignore\n (message) => /your target environment does not appear/.test(message),\n ];\n }\n }\n\n private validateOptions(compiler: Compiler): boolean {\n const manifestPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance =>\n p?.constructor?.name === 'BuildManifestPlugin',\n );\n\n if (manifestPlugin) {\n //@ts-ignore\n if (manifestPlugin?.appDirEnabled) {\n throw new Error(\n 'App Directory is not supported by nextjs-mf. Use only pages directory, do not open git issues about this',\n );\n }\n }\n\n const compilerValid = validateCompilerOptions(compiler);\n const pluginValid = validatePluginOptions(this._options);\n const envValid = process.env['NEXT_PRIVATE_LOCAL_WEBPACK'];\n if (compilerValid === undefined) logger.error('Compiler validation failed');\n if (pluginValid === undefined) logger.error('Plugin validation failed');\n const validCompilerTarget =\n compiler.options.name === 'server' || compiler.options.name === 'client';\n if (!envValid)\n throw new Error(\n 'process.env.NEXT_PRIVATE_LOCAL_WEBPACK is not set to true, please set it to true, and \"npm install webpack\"',\n );\n return (\n compilerValid !== undefined &&\n pluginValid !== undefined &&\n validCompilerTarget\n );\n }\n\n private isServerCompiler(compiler: Compiler): boolean {\n return compiler.options.name === 'server';\n }\n\n private applyConditionalPlugins(compiler: Compiler, isServer: boolean) {\n compiler.options.output.uniqueName = this._options.name;\n compiler.options.output.environment = {\n ...compiler.options.output.environment,\n asyncFunction: true,\n };\n\n // Add layer rules for resource queries\n if (!compiler.options.module.rules) {\n compiler.options.module.rules = [];\n }\n\n // Add layer rules for RSC, client and SSR\n compiler.options.module.rules.push({\n resourceQuery: /\\?rsc/,\n layer: 'rsc',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?client/,\n layer: 'client',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?ssr/,\n layer: 'ssr',\n });\n\n applyPathFixes(compiler, this._options, this._extraOptions);\n if (this._extraOptions.debug) {\n compiler.options.devtool = false;\n }\n\n if (isServer) {\n configureServerCompilerOptions(compiler);\n configureServerLibraryAndFilename(this._options);\n applyServerPlugins(compiler, this._options);\n handleServerExternals(compiler, {\n ...this._options,\n shared: { ...retrieveDefaultShared(isServer), ...this._options.shared },\n });\n } else {\n applyClientPlugins(compiler, this._options, this._extraOptions);\n }\n }\n\n private getNormalFederationPluginOptions(\n compiler: Compiler,\n isServer: boolean,\n ): moduleFederationPlugin.ModuleFederationPluginOptions {\n const defaultShared = this._extraOptions.skipSharingNextInternals\n ? {}\n : retrieveDefaultShared(isServer);\n const manifestOptions =\n typeof this._options.manifest === 'object' &&\n this._options.manifest !== null\n ? this._options.manifest\n : {};\n\n return {\n ...this._options,\n runtime: false,\n remoteType: 'script',\n runtimePlugins: [\n ...(isServer ? [resolveNodeRuntimePluginPath()] : []),\n resolveRuntimePluginPath(),\n ...(this._options.runtimePlugins || []),\n ].map((plugin) => plugin + '?runtimePlugin'),\n //@ts-ignore\n exposes: {\n ...this._options.exposes,\n ...(this._extraOptions.exposePages\n ? exposeNextjsPages(compiler.options.context as string)\n : {}),\n },\n remotes: {\n ...this._options.remotes,\n },\n shared: {\n ...defaultShared,\n ...(this._options.shared as Record<string, unknown>),\n },\n manifest: {\n ...manifestOptions,\n filePath: isServer ? '' : '/static/chunks',\n },\n // nextjs project needs to add config.watchOptions = ['**/node_modules/**', '**/@mf-types/**'] to prevent loop types update\n dts: this._options.dts ?? false,\n shareStrategy: this._options.shareStrategy ?? 'loaded-first',\n experiments: {\n asyncStartup: true,\n },\n };\n }\n\n private getNoopPath(): string {\n return resolveNoopPath();\n }\n}\n\nexport default NextFederationPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,2CAEQ,QAAQ,4EAA4E;AAGlG,MAAM,kCAEQ,QAAQ,4DAA4D;AAGlF,MAAM,qCAA6C;CACjD,MAAM,kBAAkB,KAAK,kBACnB,QAAQ,uCAAuC,CACxD;AAED,kBAAe,QACb,KAAK,KACH,iBAEI,6BAEL,CACF;;;;;AAKH,IAAa,uBAAb,MAAkC;;;;;;CAShC,YAAY,SAAsC;EAChD,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,OACvB,KAAK,SAAS,WACd,EAAE;AAER,SAAO;GACL,GAAG,KAAK;GACR,SAAS;GACT,YAAY;GACZ,gBAAgB;IACd,GAAI,WAAW,CAAC,8BAA8B,CAAC,GAAG,EAAE;IACpD,0BAA0B;IAC1B,GAAI,KAAK,SAAS,kBAAkB,EAAE;IACvC,CAAC,KAAK,WAAW,SAAS,iBAAiB;GAE5C,SAAS;IACP,GAAG,KAAK,SAAS;IACjB,GAAI,KAAK,cAAc,cACnB,kBAAkB,SAAS,QAAQ,QAAkB,GACrD,EAAE;IACP;GACD,SAAS,EACP,GAAG,KAAK,SAAS,SAClB;GACD,QAAQ;IACN,GAAG;IACH,GAAI,KAAK,SAAS;IACnB;GACD,UAAU;IACR,GAAG;IACH,UAAU,WAAW,KAAK;IAC3B;GAED,KAAK,KAAK,SAAS,OAAO;GAC1B,eAAe,KAAK,SAAS,iBAAiB;GAC9C,aAAa,EACX,cAAc,MACf;GACF;;CAGH,AAAQ,cAAsB;AAC5B,SAAO,iBAAiB"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["CopyFederationPlugin"],"sources":["../../../../src/plugins/NextFederationPlugin/index.ts"],"sourcesContent":["/**\n * MIT License http://www.opensource.org/licenses/mit-license.php\n * Author Zackary Jackson @ScriptedAlchemy\n * This module contains the NextFederationPlugin class which is a webpack plugin that handles Next.js application federation using Module Federation.\n */\n'use strict';\n\nimport type {\n NextFederationPluginExtraOptions,\n NextFederationPluginOptions,\n} from './next-fragments';\nimport type { Compiler, WebpackPluginInstance } from 'webpack';\nimport path from 'path';\nimport { getWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport CopyFederationPlugin from '../CopyFederationPlugin';\nimport { exposeNextjsPages } from '../../loaders/nextPageMapLoader';\nimport { retrieveDefaultShared, applyPathFixes } from './next-fragments';\nimport { setOptions } from './set-options';\nimport {\n validateCompilerOptions,\n validatePluginOptions,\n} from './validate-options';\nimport {\n applyServerPlugins,\n configureServerCompilerOptions,\n configureServerLibraryAndFilename,\n handleServerExternals,\n} from './apply-server-plugins';\nimport { applyClientPlugins } from './apply-client-plugins';\nimport { ModuleFederationPlugin } from '@module-federation/enhanced/webpack';\nimport { bindLoggerToCompiler } from '@module-federation/sdk';\nimport type { moduleFederationPlugin } from '@module-federation/sdk';\nimport logger from '../../logger';\nimport { normalizeManifestOptions } from './manifest-options';\n\nconst resolveRuntimePluginPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js');\n\nconst resolveNoopPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.js');\n\nconst resolveNodeRuntimePluginPath = (): string => {\n const nodePackageRoot = path.dirname(\n require.resolve('@module-federation/node/package.json'),\n );\n\n return require.resolve(\n path.join(\n nodePackageRoot,\n process.env.IS_ESM_BUILD === 'true'\n ? 'dist/src/runtimePlugin.mjs'\n : 'dist/src/runtimePlugin.js',\n ),\n );\n};\n/**\n * NextFederationPlugin is a webpack plugin that handles Next.js application federation using Module Federation.\n */\nexport class NextFederationPlugin {\n private _options: moduleFederationPlugin.ModuleFederationPluginOptions;\n private _extraOptions: NextFederationPluginExtraOptions;\n public name: string;\n /**\n * Constructs the NextFederationPlugin with the provided options.\n *\n * @param options The options to configure the plugin.\n */\n constructor(options: NextFederationPluginOptions) {\n const { mainOptions, extraOptions } = setOptions(options);\n this._options = mainOptions;\n this._extraOptions = extraOptions;\n this.name = 'ModuleFederationPlugin';\n }\n\n /**\n * The apply method is called by the webpack compiler and allows the plugin to hook into the webpack process.\n * @param compiler The webpack compiler object.\n */\n apply(compiler: Compiler) {\n bindLoggerToCompiler(logger, compiler, 'NextFederationPlugin');\n process.env['FEDERATION_WEBPACK_PATH'] =\n process.env['FEDERATION_WEBPACK_PATH'] ||\n getWebpackPath(compiler, { framework: 'nextjs' });\n if (!this.validateOptions(compiler)) return;\n const isServer = this.isServerCompiler(compiler);\n new CopyFederationPlugin(isServer).apply(compiler);\n const normalFederationPluginOptions = this.getNormalFederationPluginOptions(\n compiler,\n isServer,\n );\n this._options = normalFederationPluginOptions;\n this.applyConditionalPlugins(compiler, isServer);\n\n new ModuleFederationPlugin(normalFederationPluginOptions).apply(compiler);\n\n const noop = this.getNoopPath();\n\n if (!this._extraOptions.skipSharingNextInternals) {\n compiler.hooks.make.tapAsync(\n 'NextFederationPlugin',\n (compilation, callback) => {\n const dep = compiler.webpack.EntryPlugin.createDependency(\n noop,\n 'noop',\n );\n compilation.addEntry(\n compiler.context,\n dep,\n { name: 'noop' },\n (err, module) => {\n if (err) {\n return callback(err);\n }\n callback();\n },\n );\n },\n );\n }\n\n if (!compiler.options.ignoreWarnings) {\n compiler.options.ignoreWarnings = [\n //@ts-ignore\n (message) => /your target environment does not appear/.test(message),\n ];\n }\n }\n\n private validateOptions(compiler: Compiler): boolean {\n const manifestPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance =>\n p?.constructor?.name === 'BuildManifestPlugin',\n );\n\n if (manifestPlugin) {\n //@ts-ignore\n if (manifestPlugin?.appDirEnabled) {\n throw new Error(\n 'App Directory is not supported by nextjs-mf. Use only pages directory, do not open git issues about this',\n );\n }\n }\n\n const compilerValid = validateCompilerOptions(compiler);\n const pluginValid = validatePluginOptions(this._options);\n const envValid = process.env['NEXT_PRIVATE_LOCAL_WEBPACK'];\n if (compilerValid === undefined) logger.error('Compiler validation failed');\n if (pluginValid === undefined) logger.error('Plugin validation failed');\n const validCompilerTarget =\n compiler.options.name === 'server' || compiler.options.name === 'client';\n if (!envValid)\n throw new Error(\n 'process.env.NEXT_PRIVATE_LOCAL_WEBPACK is not set to true, please set it to true, and \"npm install webpack\"',\n );\n return (\n compilerValid !== undefined &&\n pluginValid !== undefined &&\n validCompilerTarget\n );\n }\n\n private isServerCompiler(compiler: Compiler): boolean {\n return compiler.options.name === 'server';\n }\n\n private applyConditionalPlugins(compiler: Compiler, isServer: boolean) {\n compiler.options.output.uniqueName = this._options.name;\n compiler.options.output.environment = {\n ...compiler.options.output.environment,\n asyncFunction: true,\n };\n\n // Add layer rules for resource queries\n if (!compiler.options.module.rules) {\n compiler.options.module.rules = [];\n }\n\n // Add layer rules for RSC, client and SSR\n compiler.options.module.rules.push({\n resourceQuery: /\\?rsc/,\n layer: 'rsc',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?client/,\n layer: 'client',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?ssr/,\n layer: 'ssr',\n });\n\n applyPathFixes(compiler, this._options, this._extraOptions);\n if (this._extraOptions.debug) {\n compiler.options.devtool = false;\n }\n\n if (isServer) {\n configureServerCompilerOptions(compiler);\n configureServerLibraryAndFilename(this._options);\n applyServerPlugins(compiler, this._options);\n handleServerExternals(compiler, {\n ...this._options,\n shared: { ...retrieveDefaultShared(isServer), ...this._options.shared },\n });\n } else {\n applyClientPlugins(compiler, this._options, this._extraOptions);\n }\n }\n\n private getNormalFederationPluginOptions(\n compiler: Compiler,\n isServer: boolean,\n ): moduleFederationPlugin.ModuleFederationPluginOptions {\n const defaultShared = this._extraOptions.skipSharingNextInternals\n ? {}\n : retrieveDefaultShared(isServer);\n return {\n ...this._options,\n runtime: false,\n remoteType: 'script',\n runtimePlugins: [\n ...(isServer ? [resolveNodeRuntimePluginPath()] : []),\n resolveRuntimePluginPath(),\n ...(this._options.runtimePlugins || []),\n ].map((plugin) => plugin + '?runtimePlugin'),\n //@ts-ignore\n exposes: {\n ...this._options.exposes,\n ...(this._extraOptions.exposePages\n ? exposeNextjsPages(compiler.options.context as string)\n : {}),\n },\n remotes: {\n ...this._options.remotes,\n },\n shared: {\n ...defaultShared,\n ...(this._options.shared as Record<string, unknown>),\n },\n manifest: normalizeManifestOptions(this._options.manifest, isServer),\n // nextjs project needs to add config.watchOptions = ['**/node_modules/**', '**/@mf-types/**'] to prevent loop types update\n dts: this._options.dts ?? false,\n shareStrategy: this._options.shareStrategy ?? 'loaded-first',\n experiments: {\n asyncStartup: true,\n },\n };\n }\n\n private getNoopPath(): string {\n return resolveNoopPath();\n }\n}\n\nexport default NextFederationPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,2CAEQ,QAAQ,4EAA4E;AAGlG,MAAM,kCAEQ,QAAQ,4DAA4D;AAGlF,MAAM,qCAA6C;CACjD,MAAM,kBAAkB,KAAK,kBACnB,QAAQ,uCAAuC,CACxD;AAED,kBAAe,QACb,KAAK,KACH,iBAEI,6BAEL,CACF;;;;;AAKH,IAAa,uBAAb,MAAkC;;;;;;CAShC,YAAY,SAAsC;EAChD,MAAM,EAAE,aAAa,iBAAiB,WAAW,QAAQ;AACzD,OAAK,WAAW;AAChB,OAAK,gBAAgB;AACrB,OAAK,OAAO;;;;;;CAOd,MAAM,UAAoB;AACxB,uBAAqB,QAAQ,UAAU,uBAAuB;AAC9D,UAAQ,IAAI,6BACV,QAAQ,IAAI,8BACZ,eAAe,UAAU,EAAE,WAAW,UAAU,CAAC;AACnD,MAAI,CAAC,KAAK,gBAAgB,SAAS,CAAE;EACrC,MAAM,WAAW,KAAK,iBAAiB,SAAS;AAChD,MAAIA,sBAAqB,SAAS,CAAC,MAAM,SAAS;EAClD,MAAM,gCAAgC,KAAK,iCACzC,UACA,SACD;AACD,OAAK,WAAW;AAChB,OAAK,wBAAwB,UAAU,SAAS;AAEhD,MAAI,uBAAuB,8BAA8B,CAAC,MAAM,SAAS;EAEzE,MAAM,OAAO,KAAK,aAAa;AAE/B,MAAI,CAAC,KAAK,cAAc,yBACtB,UAAS,MAAM,KAAK,SAClB,yBACC,aAAa,aAAa;GACzB,MAAM,MAAM,SAAS,QAAQ,YAAY,iBACvC,MACA,OACD;AACD,eAAY,SACV,SAAS,SACT,KACA,EAAE,MAAM,QAAQ,GACf,KAAK,WAAW;AACf,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AAc;AAC3D,MAAI,KAAK,cAAc,MACrB,UAAS,QAAQ,UAAU;AAG7B,MAAI,UAAU;AACZ,kCAA+B,SAAS;AACxC,qCAAkC,KAAK,SAAS;AAChD,sBAAmB,UAAU,KAAK,SAAS;AAC3C,yBAAsB,UAAU;IAC9B,GAAG,KAAK;IACR,QAAQ;KAAE,GAAG,sBAAsB,SAAS;KAAE,GAAG,KAAK,SAAS;KAAQ;IACxE,CAAC;QAEF,oBAAmB,UAAU,KAAK,UAAU,KAAK,cAAc;;CAInE,AAAQ,iCACN,UACA,UACsD;EACtD,MAAM,gBAAgB,KAAK,cAAc,2BACrC,EAAE,GACF,sBAAsB,SAAS;AACnC,SAAO;GACL,GAAG,KAAK;GACR,SAAS;GACT,YAAY;GACZ,gBAAgB;IACd,GAAI,WAAW,CAAC,8BAA8B,CAAC,GAAG,EAAE;IACpD,0BAA0B;IAC1B,GAAI,KAAK,SAAS,kBAAkB,EAAE;IACvC,CAAC,KAAK,WAAW,SAAS,iBAAiB;GAE5C,SAAS;IACP,GAAG,KAAK,SAAS;IACjB,GAAI,KAAK,cAAc,cACnB,kBAAkB,SAAS,QAAQ,QAAkB,GACrD,EAAE;IACP;GACD,SAAS,EACP,GAAG,KAAK,SAAS,SAClB;GACD,QAAQ;IACN,GAAG;IACH,GAAI,KAAK,SAAS;IACnB;GACD,UAAU,yBAAyB,KAAK,SAAS,UAAU,SAAS;GAEpE,KAAK,KAAK,SAAS,OAAO;GAC1B,eAAe,KAAK,SAAS,iBAAiB;GAC9C,aAAa,EACX,cAAc,MACf;GACF;;CAGH,AAAQ,cAAsB;AAC5B,SAAO,iBAAiB"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
|
+
type ManifestOptions = moduleFederationPlugin.ModuleFederationPluginOptions['manifest'];
|
|
3
|
+
export declare const normalizeManifestOptions: (manifest: ManifestOptions, isServer: boolean) => ManifestOptions;
|
|
4
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
|
+
type ManifestOptions = moduleFederationPlugin.ModuleFederationPluginOptions['manifest'];
|
|
3
|
+
export declare const normalizeManifestOptions: (manifest: ManifestOptions, isServer: boolean) => ManifestOptions;
|
|
4
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/plugins/NextFederationPlugin/manifest-options.ts
|
|
3
|
+
const normalizeManifestOptions = (manifest, isServer) => {
|
|
4
|
+
if (manifest === false) return false;
|
|
5
|
+
return {
|
|
6
|
+
...typeof manifest === "object" && manifest !== null ? manifest : {},
|
|
7
|
+
filePath: isServer ? "" : "/static/chunks"
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.normalizeManifestOptions = normalizeManifestOptions;
|
|
13
|
+
//# sourceMappingURL=manifest-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest-options.js","names":[],"sources":["../../../../src/plugins/NextFederationPlugin/manifest-options.ts"],"sourcesContent":["import type { moduleFederationPlugin } from '@module-federation/sdk';\n\ntype ManifestOptions =\n moduleFederationPlugin.ModuleFederationPluginOptions['manifest'];\n\nexport const normalizeManifestOptions = (\n manifest: ManifestOptions,\n isServer: boolean,\n): ManifestOptions => {\n if (manifest === false) return false;\n\n return {\n ...(typeof manifest === 'object' && manifest !== null ? manifest : {}),\n filePath: isServer ? '' : '/static/chunks',\n };\n};\n"],"mappings":";;AAKA,MAAa,4BACX,UACA,aACoB;AACpB,KAAI,aAAa,MAAO,QAAO;AAE/B,QAAO;EACL,GAAI,OAAO,aAAa,YAAY,aAAa,OAAO,WAAW,EAAE;EACrE,UAAU,WAAW,KAAK;EAC3B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/plugins/NextFederationPlugin/manifest-options.ts
|
|
2
|
+
const normalizeManifestOptions = (manifest, isServer) => {
|
|
3
|
+
if (manifest === false) return false;
|
|
4
|
+
return {
|
|
5
|
+
...typeof manifest === "object" && manifest !== null ? manifest : {},
|
|
6
|
+
filePath: isServer ? "" : "/static/chunks"
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { normalizeManifestOptions };
|
|
12
|
+
//# sourceMappingURL=manifest-options.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest-options.mjs","names":[],"sources":["../../../../src/plugins/NextFederationPlugin/manifest-options.ts"],"sourcesContent":["import type { moduleFederationPlugin } from '@module-federation/sdk';\n\ntype ManifestOptions =\n moduleFederationPlugin.ModuleFederationPluginOptions['manifest'];\n\nexport const normalizeManifestOptions = (\n manifest: ManifestOptions,\n isServer: boolean,\n): ManifestOptions => {\n if (manifest === false) return false;\n\n return {\n ...(typeof manifest === 'object' && manifest !== null ? manifest : {}),\n filePath: isServer ? '' : '/static/chunks',\n };\n};\n"],"mappings":";AAKA,MAAa,4BACX,UACA,aACoB;AACpB,KAAI,aAAa,MAAO,QAAO;AAE/B,QAAO;EACL,GAAI,OAAO,aAAa,YAAY,aAAa,OAAO,WAAW,EAAE;EACrE,UAAU,WAAW,KAAK;EAC3B"}
|
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
import type { moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
|
-
|
|
3
|
-
enableImageLoaderFix?: boolean;
|
|
4
|
-
enableUrlLoaderFix?: boolean;
|
|
5
|
-
exposePages?: boolean;
|
|
6
|
-
skipSharingNextInternals?: boolean;
|
|
7
|
-
automaticPageStitching?: boolean;
|
|
8
|
-
debug?: boolean;
|
|
9
|
-
}
|
|
10
|
-
export interface NextFederationPluginOptions extends moduleFederationPlugin.ModuleFederationPluginOptions {
|
|
11
|
-
extraOptions: NextFederationPluginExtraOptions;
|
|
12
|
-
}
|
|
2
|
+
import type { NextFederationPluginExtraOptions, NextFederationPluginOptions } from './next-fragments';
|
|
13
3
|
export declare function setOptions(options: NextFederationPluginOptions): {
|
|
14
4
|
mainOptions: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
15
5
|
extraOptions: NextFederationPluginExtraOptions;
|
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
import type { moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
|
-
|
|
3
|
-
enableImageLoaderFix?: boolean;
|
|
4
|
-
enableUrlLoaderFix?: boolean;
|
|
5
|
-
exposePages?: boolean;
|
|
6
|
-
skipSharingNextInternals?: boolean;
|
|
7
|
-
automaticPageStitching?: boolean;
|
|
8
|
-
debug?: boolean;
|
|
9
|
-
}
|
|
10
|
-
export interface NextFederationPluginOptions extends moduleFederationPlugin.ModuleFederationPluginOptions {
|
|
11
|
-
extraOptions: NextFederationPluginExtraOptions;
|
|
12
|
-
}
|
|
2
|
+
import type { NextFederationPluginExtraOptions, NextFederationPluginOptions } from './next-fragments';
|
|
13
3
|
export declare function setOptions(options: NextFederationPluginOptions): {
|
|
14
4
|
mainOptions: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
15
5
|
extraOptions: NextFederationPluginExtraOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-options.js","names":[],"sources":["../../../../src/plugins/NextFederationPlugin/set-options.ts"],"sourcesContent":["import type { moduleFederationPlugin } from '@module-federation/sdk';\
|
|
1
|
+
{"version":3,"file":"set-options.js","names":[],"sources":["../../../../src/plugins/NextFederationPlugin/set-options.ts"],"sourcesContent":["import type { moduleFederationPlugin } from '@module-federation/sdk';\nimport type {\n NextFederationPluginExtraOptions,\n NextFederationPluginOptions,\n} from './next-fragments';\n\nexport function setOptions(options: NextFederationPluginOptions): {\n mainOptions: moduleFederationPlugin.ModuleFederationPluginOptions;\n extraOptions: NextFederationPluginExtraOptions;\n} {\n const { extraOptions, ...mainOpts } = options;\n\n /**\n * Default extra options for NextFederationPlugin.\n * @type {NextFederationPluginExtraOptions}\n */\n const defaultExtraOptions: NextFederationPluginExtraOptions = {\n automaticPageStitching: false,\n enableImageLoaderFix: false,\n enableUrlLoaderFix: false,\n skipSharingNextInternals: false,\n debug: false,\n };\n\n return {\n mainOptions: mainOpts,\n extraOptions: { ...defaultExtraOptions, ...extraOptions },\n };\n}\n"],"mappings":";;AAMA,SAAgB,WAAW,SAGzB;CACA,MAAM,EAAE,cAAc,GAAG,aAAa;AActC,QAAO;EACL,aAAa;EACb,cAAc;GATd,wBAAwB;GACxB,sBAAsB;GACtB,oBAAoB;GACpB,0BAA0B;GAC1B,OAAO;GAKiC,GAAG;GAAc;EAC1D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-options.mjs","names":[],"sources":["../../../../src/plugins/NextFederationPlugin/set-options.ts"],"sourcesContent":["import type { moduleFederationPlugin } from '@module-federation/sdk';\
|
|
1
|
+
{"version":3,"file":"set-options.mjs","names":[],"sources":["../../../../src/plugins/NextFederationPlugin/set-options.ts"],"sourcesContent":["import type { moduleFederationPlugin } from '@module-federation/sdk';\nimport type {\n NextFederationPluginExtraOptions,\n NextFederationPluginOptions,\n} from './next-fragments';\n\nexport function setOptions(options: NextFederationPluginOptions): {\n mainOptions: moduleFederationPlugin.ModuleFederationPluginOptions;\n extraOptions: NextFederationPluginExtraOptions;\n} {\n const { extraOptions, ...mainOpts } = options;\n\n /**\n * Default extra options for NextFederationPlugin.\n * @type {NextFederationPluginExtraOptions}\n */\n const defaultExtraOptions: NextFederationPluginExtraOptions = {\n automaticPageStitching: false,\n enableImageLoaderFix: false,\n enableUrlLoaderFix: false,\n skipSharingNextInternals: false,\n debug: false,\n };\n\n return {\n mainOptions: mainOpts,\n extraOptions: { ...defaultExtraOptions, ...extraOptions },\n };\n}\n"],"mappings":";AAMA,SAAgB,WAAW,SAGzB;CACA,MAAM,EAAE,cAAc,GAAG,aAAa;AActC,QAAO;EACL,aAAa;EACb,cAAc;GATd,wBAAwB;GACxB,sBAAsB;GACtB,oBAAoB;GACpB,0BAA0B;GAC1B,OAAO;GAKiC,GAAG;GAAc;EAC1D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/nextjs-mf",
|
|
3
|
-
"version": "8.8.
|
|
3
|
+
"version": "8.8.72",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"module": "dist/src/index.mjs",
|
|
@@ -58,12 +58,12 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"fast-glob": "^3.2.11",
|
|
61
|
-
"@module-federation/runtime": "2.8.
|
|
62
|
-
"@module-federation/
|
|
63
|
-
"@module-federation/
|
|
64
|
-
"@module-federation/
|
|
65
|
-
"@module-federation/
|
|
66
|
-
"@module-federation/
|
|
61
|
+
"@module-federation/runtime": "2.8.1",
|
|
62
|
+
"@module-federation/runtime-core": "2.8.1",
|
|
63
|
+
"@module-federation/node": "2.7.48",
|
|
64
|
+
"@module-federation/webpack-bundler-runtime": "2.8.1",
|
|
65
|
+
"@module-federation/enhanced": "2.8.1",
|
|
66
|
+
"@module-federation/sdk": "2.8.1"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@types/btoa": "^1.2.5",
|