@module-federation/nextjs-mf 8.8.57 → 8.8.58
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/loaders/fixImageLoader.js +1 -1
- package/dist/src/loaders/fixImageLoader.mjs +1 -1
- package/dist/src/plugins/CopyFederationPlugin.js +1 -1
- package/dist/src/plugins/CopyFederationPlugin.mjs +1 -1
- package/dist/src/plugins/NextFederationPlugin/index.js +14 -10
- package/dist/src/plugins/NextFederationPlugin/index.js.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/index.mjs +13 -10
- package/dist/src/plugins/NextFederationPlugin/index.mjs.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/next-fragments.js +4 -9
- package/dist/src/plugins/NextFederationPlugin/next-fragments.js.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/next-fragments.mjs +4 -9
- package/dist/src/plugins/NextFederationPlugin/next-fragments.mjs.map +1 -1
- package/dist/src/plugins/container/InvertedContainerPlugin.js +5 -4
- package/dist/src/plugins/container/InvertedContainerPlugin.js.map +1 -1
- package/dist/src/plugins/container/InvertedContainerPlugin.mjs +6 -2
- package/dist/src/plugins/container/InvertedContainerPlugin.mjs.map +1 -1
- package/package.json +11 -7
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
3
|
-
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
4
3
|
let path = require("path");
|
|
5
4
|
path = require_runtime.__toESM(path);
|
|
5
|
+
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
6
6
|
|
|
7
7
|
//#region src/loaders/fixImageLoader.ts
|
|
8
8
|
const { Template } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __require } from "../../_virtual/_rolldown/runtime.mjs";
|
|
2
|
-
import { normalizeWebpackPath } from "@module-federation/sdk/normalize-webpack-path";
|
|
3
2
|
import path from "path";
|
|
3
|
+
import { normalizeWebpackPath } from "@module-federation/sdk/normalize-webpack-path";
|
|
4
4
|
|
|
5
5
|
//#region src/loaders/fixImageLoader.ts
|
|
6
6
|
const { Template } = __require(normalizeWebpackPath("webpack"));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
2
2
|
const require_logger = require('../logger.js');
|
|
3
|
-
let fs = require("fs");
|
|
4
3
|
let path = require("path");
|
|
5
4
|
path = require_runtime.__toESM(path);
|
|
5
|
+
let fs = require("fs");
|
|
6
6
|
let _module_federation_sdk = require("@module-federation/sdk");
|
|
7
7
|
|
|
8
8
|
//#region src/plugins/CopyFederationPlugin.ts
|
|
@@ -9,6 +9,8 @@ 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
|
+
let path = require("path");
|
|
13
|
+
path = require_runtime.__toESM(path);
|
|
12
14
|
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
13
15
|
let _module_federation_sdk = require("@module-federation/sdk");
|
|
14
16
|
let _module_federation_enhanced_webpack = require("@module-federation/enhanced/webpack");
|
|
@@ -19,12 +21,11 @@ let _module_federation_enhanced_webpack = require("@module-federation/enhanced/w
|
|
|
19
21
|
* Author Zackary Jackson @ScriptedAlchemy
|
|
20
22
|
* This module contains the NextFederationPlugin class which is a webpack plugin that handles Next.js application federation using Module Federation.
|
|
21
23
|
*/
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
24
|
+
const resolveRuntimePluginPath = () => require.resolve("@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js");
|
|
25
|
+
const resolveNoopPath = () => require.resolve("@module-federation/nextjs-mf/dist/src/federation-noop.js");
|
|
26
|
+
const resolveNodeRuntimePluginPath = () => {
|
|
27
|
+
const nodePackageRoot = path.default.dirname(require.resolve("@module-federation/node/package.json"));
|
|
28
|
+
return require.resolve(path.default.join(nodePackageRoot, "dist/src/runtimePlugin.js"));
|
|
28
29
|
};
|
|
29
30
|
/**
|
|
30
31
|
* NextFederationPlugin is a webpack plugin that handles Next.js application federation using Module Federation.
|
|
@@ -123,8 +124,8 @@ var NextFederationPlugin = class {
|
|
|
123
124
|
runtime: false,
|
|
124
125
|
remoteType: "script",
|
|
125
126
|
runtimePlugins: [
|
|
126
|
-
...isServer ? [
|
|
127
|
-
|
|
127
|
+
...isServer ? [resolveNodeRuntimePluginPath()] : [],
|
|
128
|
+
resolveRuntimePluginPath(),
|
|
128
129
|
...this._options.runtimePlugins || []
|
|
129
130
|
].map((plugin) => plugin + "?runtimePlugin"),
|
|
130
131
|
exposes: {
|
|
@@ -136,14 +137,17 @@ var NextFederationPlugin = class {
|
|
|
136
137
|
...defaultShared,
|
|
137
138
|
...this._options.shared
|
|
138
139
|
},
|
|
139
|
-
|
|
140
|
+
manifest: {
|
|
141
|
+
...this._options.manifest ?? {},
|
|
142
|
+
filePath: isServer ? "" : "/static/chunks"
|
|
143
|
+
},
|
|
140
144
|
dts: this._options.dts ?? false,
|
|
141
145
|
shareStrategy: this._options.shareStrategy ?? "loaded-first",
|
|
142
146
|
experiments: { asyncStartup: true }
|
|
143
147
|
};
|
|
144
148
|
}
|
|
145
149
|
getNoopPath() {
|
|
146
|
-
return
|
|
150
|
+
return resolveNoopPath();
|
|
147
151
|
}
|
|
148
152
|
};
|
|
149
153
|
|
|
@@ -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 { 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 resolveDistOrLocalPath = (\n packageDistPath: string,\n localRelativePath: string,\n): string => {\n try {\n return require.resolve(packageDistPath);\n } catch {\n return require.resolve(localRelativePath);\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\n return {\n ...this._options,\n runtime: false,\n remoteType: 'script',\n runtimePlugins: [\n ...(isServer\n ? [require.resolve('@module-federation/node/runtimePlugin')]\n : []),\n resolveDistOrLocalPath(\n '@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js',\n '../container/runtimePlugin.js',\n ),\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,\n },\n ...(isServer\n ? { manifest: { filePath: '' } }\n : { manifest: { filePath: '/static/chunks' } }),\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 resolveDistOrLocalPath(\n '@module-federation/nextjs-mf/dist/src/federation-noop.js',\n '../../federation-noop.js',\n );\n }\n}\n\nexport default NextFederationPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAiCA,MAAM,0BACJ,iBACA,sBACW;AACX,KAAI;AACF,SAAO,QAAQ,QAAQ,gBAAgB;SACjC;AACN,SAAO,QAAQ,QAAQ,kBAAkB;;;;;;AAM7C,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,gBAAgB,SAAS,CAAE;EACrC,MAAM,WAAW,KAAK,iBAAiB,SAAS;AAChD,MAAIC,qCAAqB,SAAS,CAAC,MAAM,SAAS;EAClD,MAAM,gCAAgC,KAAK,iCACzC,UACA,SACD;AACD,OAAK,WAAW;AAChB,OAAK,wBAAwB,UAAU,SAAS;AAEhD,MAAIC,2DAAuB,8BAA8B,CAAC,MAAM,SAAS;EAEzE,MAAM,OAAO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iBAAiB;GAC9C,aAAa,EACX,cAAc,MACf;GACF;;CAGH,AAAQ,cAAsB;AAC5B,SAAO,uBACL,4DACA,2BACD"}
|
|
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(\n '@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.mjs',\n )\n : require.resolve(\n '@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js',\n );\n\nconst resolveNoopPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve(\n '@module-federation/nextjs-mf/dist/src/federation-noop.mjs',\n )\n : require.resolve(\n '@module-federation/nextjs-mf/dist/src/federation-noop.js',\n );\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\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,\n },\n manifest: {\n ...(this._options.manifest ?? {}),\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\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,iCAKA,QAAQ,QACN,2EACD;AAEP,MAAM,wBAKA,QAAQ,QACN,2DACD;AAEP,MAAM,qCAA6C;CACjD,MAAM,kBAAkB,aAAK,QAC3B,QAAQ,QAAQ,uCAAuC,CACxD;AAED,QAAO,QAAQ,QACb,aAAK,KACH,iBAGI,4BACL,CACF;;;;;AAKH,IA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O;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,GAAG,KAAK,SAAS;IAClB;GACD,UAAU;IACR,GAAI,KAAK,SAAS,YAAY,EAAE;IAChC,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"}
|
|
@@ -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 path from "path";
|
|
10
11
|
import { getWebpackPath } from "@module-federation/sdk/normalize-webpack-path";
|
|
11
12
|
import { bindLoggerToCompiler } from "@module-federation/sdk";
|
|
12
13
|
import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
|
|
@@ -17,12 +18,11 @@ import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
|
|
|
17
18
|
* Author Zackary Jackson @ScriptedAlchemy
|
|
18
19
|
* This module contains the NextFederationPlugin class which is a webpack plugin that handles Next.js application federation using Module Federation.
|
|
19
20
|
*/
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
21
|
+
const resolveRuntimePluginPath = () => __require.resolve("@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.mjs");
|
|
22
|
+
const resolveNoopPath = () => __require.resolve("@module-federation/nextjs-mf/dist/src/federation-noop.mjs");
|
|
23
|
+
const resolveNodeRuntimePluginPath = () => {
|
|
24
|
+
const nodePackageRoot = path.dirname(__require.resolve("@module-federation/node/package.json"));
|
|
25
|
+
return __require.resolve(path.join(nodePackageRoot, "dist/src/runtimePlugin.mjs"));
|
|
26
26
|
};
|
|
27
27
|
/**
|
|
28
28
|
* NextFederationPlugin is a webpack plugin that handles Next.js application federation using Module Federation.
|
|
@@ -121,8 +121,8 @@ var NextFederationPlugin = class {
|
|
|
121
121
|
runtime: false,
|
|
122
122
|
remoteType: "script",
|
|
123
123
|
runtimePlugins: [
|
|
124
|
-
...isServer ? [
|
|
125
|
-
|
|
124
|
+
...isServer ? [resolveNodeRuntimePluginPath()] : [],
|
|
125
|
+
resolveRuntimePluginPath(),
|
|
126
126
|
...this._options.runtimePlugins || []
|
|
127
127
|
].map((plugin) => plugin + "?runtimePlugin"),
|
|
128
128
|
exposes: {
|
|
@@ -134,14 +134,17 @@ var NextFederationPlugin = class {
|
|
|
134
134
|
...defaultShared,
|
|
135
135
|
...this._options.shared
|
|
136
136
|
},
|
|
137
|
-
|
|
137
|
+
manifest: {
|
|
138
|
+
...this._options.manifest ?? {},
|
|
139
|
+
filePath: isServer ? "" : "/static/chunks"
|
|
140
|
+
},
|
|
138
141
|
dts: this._options.dts ?? false,
|
|
139
142
|
shareStrategy: this._options.shareStrategy ?? "loaded-first",
|
|
140
143
|
experiments: { asyncStartup: true }
|
|
141
144
|
};
|
|
142
145
|
}
|
|
143
146
|
getNoopPath() {
|
|
144
|
-
return
|
|
147
|
+
return resolveNoopPath();
|
|
145
148
|
}
|
|
146
149
|
};
|
|
147
150
|
|
|
@@ -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 { 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 resolveDistOrLocalPath = (\n packageDistPath: string,\n localRelativePath: string,\n): string => {\n try {\n return require.resolve(packageDistPath);\n } catch {\n return require.resolve(localRelativePath);\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\n return {\n ...this._options,\n runtime: false,\n remoteType: 'script',\n runtimePlugins: [\n ...(isServer\n ? [require.resolve('@module-federation/node/runtimePlugin')]\n : []),\n resolveDistOrLocalPath(\n '@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js',\n '../container/runtimePlugin.js',\n ),\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,\n },\n ...(isServer\n ? { manifest: { filePath: '' } }\n : { manifest: { filePath: '/static/chunks' } }),\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 resolveDistOrLocalPath(\n '@module-federation/nextjs-mf/dist/src/federation-noop.js',\n '../../federation-noop.js',\n );\n }\n}\n\nexport default NextFederationPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiCA,MAAM,0BACJ,iBACA,sBACW;AACX,KAAI;AACF,mBAAe,QAAQ,gBAAgB;SACjC;AACN,mBAAe,QAAQ,kBAAkB;;;;;;AAM7C,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,OA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C,aAAa,EACX,cAAc,MACf;GACF;;CAGH,AAAQ,cAAsB;AAC5B,SAAO,uBACL,4DACA,2BACD"}
|
|
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(\n '@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.mjs',\n )\n : require.resolve(\n '@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js',\n );\n\nconst resolveNoopPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve(\n '@module-federation/nextjs-mf/dist/src/federation-noop.mjs',\n )\n : require.resolve(\n '@module-federation/nextjs-mf/dist/src/federation-noop.js',\n );\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\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,\n },\n manifest: {\n ...(this._options.manifest ?? {}),\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\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,2CAEQ,QACN,4EACD;AAKP,MAAM,kCAEQ,QACN,4DACD;AAKP,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;AACh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B;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,GAAG,KAAK,SAAS;IAClB;GACD,UAAU;IACR,GAAI,KAAK,SAAS,YAAY,EAAE;IAChC,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"}
|
|
@@ -5,13 +5,8 @@ let path = require("path");
|
|
|
5
5
|
path = require_runtime.__toESM(path);
|
|
6
6
|
|
|
7
7
|
//#region src/plugins/NextFederationPlugin/next-fragments.ts
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
return require.resolve(packageDistPath);
|
|
11
|
-
} catch {
|
|
12
|
-
return require.resolve(localRelativePath);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
8
|
+
const resolveFixImageLoaderPath = () => require.resolve("@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.js");
|
|
9
|
+
const resolveFixUrlLoaderPath = () => require.resolve("@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.js");
|
|
15
10
|
/**
|
|
16
11
|
* Set up default shared values based on the environment.
|
|
17
12
|
* @param {boolean} isServer - Boolean indicating if the code is running on the server.
|
|
@@ -30,8 +25,8 @@ const applyPathFixes = (compiler, pluginOptions, options) => {
|
|
|
30
25
|
compiler.options.module.rules.forEach((rule) => {
|
|
31
26
|
if (typeof rule === "object" && rule !== null) {
|
|
32
27
|
const typedRule = rule;
|
|
33
|
-
if (options.enableImageLoaderFix && require_helpers.hasLoader(typedRule, "next-image-loader")) require_helpers.injectRuleLoader(typedRule, { loader:
|
|
34
|
-
if (options.enableUrlLoaderFix && require_helpers.hasLoader(typedRule, "url-loader")) require_helpers.injectRuleLoader(typedRule, { loader:
|
|
28
|
+
if (options.enableImageLoaderFix && require_helpers.hasLoader(typedRule, "next-image-loader")) require_helpers.injectRuleLoader(typedRule, { loader: resolveFixImageLoaderPath() });
|
|
29
|
+
if (options.enableUrlLoaderFix && require_helpers.hasLoader(typedRule, "url-loader")) require_helpers.injectRuleLoader(typedRule, { loader: resolveFixUrlLoaderPath() });
|
|
35
30
|
}
|
|
36
31
|
});
|
|
37
32
|
if (match) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-fragments.js","names":["DEFAULT_SHARE_SCOPE","DEFAULT_SHARE_SCOPE_BROWSER","findLoaderForResource","hasLoader"],"sources":["../../../../src/plugins/NextFederationPlugin/next-fragments.ts"],"sourcesContent":["import type { Compiler, RuleSetRule } from 'webpack';\nimport type {\n moduleFederationPlugin,\n sharePlugin,\n} from '@module-federation/sdk';\nimport {\n DEFAULT_SHARE_SCOPE,\n DEFAULT_SHARE_SCOPE_BROWSER,\n} from '../../internal';\nimport {\n hasLoader,\n injectRuleLoader,\n findLoaderForResource,\n} from '../../loaders/helpers';\nimport path from 'path';\n\nconst
|
|
1
|
+
{"version":3,"file":"next-fragments.js","names":["DEFAULT_SHARE_SCOPE","DEFAULT_SHARE_SCOPE_BROWSER","findLoaderForResource","hasLoader"],"sources":["../../../../src/plugins/NextFederationPlugin/next-fragments.ts"],"sourcesContent":["import type { Compiler, RuleSetRule } from 'webpack';\nimport type {\n moduleFederationPlugin,\n sharePlugin,\n} from '@module-federation/sdk';\nimport {\n DEFAULT_SHARE_SCOPE,\n DEFAULT_SHARE_SCOPE_BROWSER,\n} from '../../internal';\nimport {\n hasLoader,\n injectRuleLoader,\n findLoaderForResource,\n} from '../../loaders/helpers';\nimport path from 'path';\n\nconst resolveFixImageLoaderPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve(\n '@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.mjs',\n )\n : require.resolve(\n '@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.js',\n );\n\nconst resolveFixUrlLoaderPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve(\n '@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.mjs',\n )\n : require.resolve(\n '@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.js',\n );\n/**\n * Set up default shared values based on the environment.\n * @param {boolean} isServer - Boolean indicating if the code is running on the server.\n * @returns {SharedObject} The default share scope based on the environment.\n */\nexport const retrieveDefaultShared = (\n isServer: boolean,\n): moduleFederationPlugin.SharedObject => {\n // If the code is running on the server, treat some Next.js internals as import false to make them external\n // This is because they will be provided by the server environment and not by the remote container\n if (isServer) {\n return DEFAULT_SHARE_SCOPE;\n }\n // If the code is running on the client/browser, always bundle Next.js internals\n return DEFAULT_SHARE_SCOPE_BROWSER;\n};\nexport const applyPathFixes = (\n compiler: Compiler,\n pluginOptions: moduleFederationPlugin.ModuleFederationPluginOptions,\n options: any,\n) => {\n const match = findLoaderForResource(\n compiler.options.module.rules as RuleSetRule[],\n {\n path: path.join(compiler.context, '/something/thing.js'),\n issuerLayer: undefined,\n layer: undefined,\n },\n );\n\n compiler.options.module.rules.forEach((rule) => {\n if (typeof rule === 'object' && rule !== null) {\n const typedRule = rule as RuleSetRule;\n // next-image-loader fix which adds remote's hostname to the assets url\n if (\n options.enableImageLoaderFix &&\n hasLoader(typedRule, 'next-image-loader')\n ) {\n injectRuleLoader(typedRule, {\n loader: resolveFixImageLoaderPath(),\n });\n }\n\n if (options.enableUrlLoaderFix && hasLoader(typedRule, 'url-loader')) {\n injectRuleLoader(typedRule, {\n loader: resolveFixUrlLoaderPath(),\n });\n }\n }\n });\n\n if (match) {\n let matchCopy: RuleSetRule;\n if (match.use) {\n matchCopy = { ...match };\n if (Array.isArray(match.use)) {\n matchCopy.use = match.use.filter((loader: any) => {\n return (\n typeof loader === 'object' &&\n loader.loader &&\n !loader.loader.includes('react')\n );\n });\n } else if (typeof match.use === 'string') {\n matchCopy.use = match.use.includes('react') ? '' : match.use;\n } else if (typeof match.use === 'object' && match.use !== null) {\n matchCopy.use =\n match.use.loader && match.use.loader.includes('react')\n ? {}\n : match.use;\n }\n } else {\n matchCopy = { ...match };\n }\n\n const descriptionDataRule: RuleSetRule = {\n ...matchCopy,\n descriptionData: {\n name: /^(@module-federation)/,\n },\n exclude: undefined,\n include: undefined,\n };\n\n const testRule: RuleSetRule = {\n ...matchCopy,\n resourceQuery: /runtimePlugin/,\n exclude: undefined,\n include: undefined,\n };\n\n const oneOfRule = compiler.options.module.rules.find(\n (rule): rule is RuleSetRule => {\n return !!rule && typeof rule === 'object' && 'oneOf' in rule;\n },\n ) as RuleSetRule | undefined;\n\n if (!oneOfRule) {\n compiler.options.module.rules.unshift({\n oneOf: [descriptionDataRule, testRule],\n });\n } else if (oneOfRule.oneOf) {\n oneOfRule.oneOf.unshift(descriptionDataRule, testRule);\n }\n }\n};\n\nexport interface NextFederationPluginExtraOptions {\n enableImageLoaderFix?: boolean;\n enableUrlLoaderFix?: boolean;\n exposePages?: boolean;\n skipSharingNextInternals?: boolean;\n automaticPageStitching?: boolean;\n debug?: boolean;\n}\n\nexport interface NextFederationPluginOptions\n extends moduleFederationPlugin.ModuleFederationPluginOptions {\n extraOptions: NextFederationPluginExtraOptions;\n}\n"],"mappings":";;;;;;;AAgBA,MAAM,kCAKA,QAAQ,QACN,kEACD;AAEP,MAAM,gCAKA,QAAQ,QACN,gEACD;;;;;;AAMP,MAAa,yBACX,aACwC;AAGxC,KAAI,SACF,QAAOA;AAGT,QAAOC;;AAET,MAAa,kBACX,UACA,eACA,YACG;CACH,MAAM,QAAQC,sCACZ,SAAS,QAAQ,OAAO,OACxB;EACE,MAAM,aAAK,KAAK,SAAS,SAAS,sBAAsB;EACxD,aAAa;EACb,OAAO;EACR,CACF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qB,SAAS"}
|
|
@@ -4,13 +4,8 @@ import { findLoaderForResource, hasLoader, injectRuleLoader } from "../../loader
|
|
|
4
4
|
import path from "path";
|
|
5
5
|
|
|
6
6
|
//#region src/plugins/NextFederationPlugin/next-fragments.ts
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
return __require.resolve(packageDistPath);
|
|
10
|
-
} catch {
|
|
11
|
-
return __require.resolve(localRelativePath);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
7
|
+
const resolveFixImageLoaderPath = () => __require.resolve("@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.mjs");
|
|
8
|
+
const resolveFixUrlLoaderPath = () => __require.resolve("@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.mjs");
|
|
14
9
|
/**
|
|
15
10
|
* Set up default shared values based on the environment.
|
|
16
11
|
* @param {boolean} isServer - Boolean indicating if the code is running on the server.
|
|
@@ -29,8 +24,8 @@ const applyPathFixes = (compiler, pluginOptions, options) => {
|
|
|
29
24
|
compiler.options.module.rules.forEach((rule) => {
|
|
30
25
|
if (typeof rule === "object" && rule !== null) {
|
|
31
26
|
const typedRule = rule;
|
|
32
|
-
if (options.enableImageLoaderFix && hasLoader(typedRule, "next-image-loader")) injectRuleLoader(typedRule, { loader:
|
|
33
|
-
if (options.enableUrlLoaderFix && hasLoader(typedRule, "url-loader")) injectRuleLoader(typedRule, { loader:
|
|
27
|
+
if (options.enableImageLoaderFix && hasLoader(typedRule, "next-image-loader")) injectRuleLoader(typedRule, { loader: resolveFixImageLoaderPath() });
|
|
28
|
+
if (options.enableUrlLoaderFix && hasLoader(typedRule, "url-loader")) injectRuleLoader(typedRule, { loader: resolveFixUrlLoaderPath() });
|
|
34
29
|
}
|
|
35
30
|
});
|
|
36
31
|
if (match) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-fragments.mjs","names":[],"sources":["../../../../src/plugins/NextFederationPlugin/next-fragments.ts"],"sourcesContent":["import type { Compiler, RuleSetRule } from 'webpack';\nimport type {\n moduleFederationPlugin,\n sharePlugin,\n} from '@module-federation/sdk';\nimport {\n DEFAULT_SHARE_SCOPE,\n DEFAULT_SHARE_SCOPE_BROWSER,\n} from '../../internal';\nimport {\n hasLoader,\n injectRuleLoader,\n findLoaderForResource,\n} from '../../loaders/helpers';\nimport path from 'path';\n\nconst
|
|
1
|
+
{"version":3,"file":"next-fragments.mjs","names":[],"sources":["../../../../src/plugins/NextFederationPlugin/next-fragments.ts"],"sourcesContent":["import type { Compiler, RuleSetRule } from 'webpack';\nimport type {\n moduleFederationPlugin,\n sharePlugin,\n} from '@module-federation/sdk';\nimport {\n DEFAULT_SHARE_SCOPE,\n DEFAULT_SHARE_SCOPE_BROWSER,\n} from '../../internal';\nimport {\n hasLoader,\n injectRuleLoader,\n findLoaderForResource,\n} from '../../loaders/helpers';\nimport path from 'path';\n\nconst resolveFixImageLoaderPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve(\n '@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.mjs',\n )\n : require.resolve(\n '@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.js',\n );\n\nconst resolveFixUrlLoaderPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve(\n '@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.mjs',\n )\n : require.resolve(\n '@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.js',\n );\n/**\n * Set up default shared values based on the environment.\n * @param {boolean} isServer - Boolean indicating if the code is running on the server.\n * @returns {SharedObject} The default share scope based on the environment.\n */\nexport const retrieveDefaultShared = (\n isServer: boolean,\n): moduleFederationPlugin.SharedObject => {\n // If the code is running on the server, treat some Next.js internals as import false to make them external\n // This is because they will be provided by the server environment and not by the remote container\n if (isServer) {\n return DEFAULT_SHARE_SCOPE;\n }\n // If the code is running on the client/browser, always bundle Next.js internals\n return DEFAULT_SHARE_SCOPE_BROWSER;\n};\nexport const applyPathFixes = (\n compiler: Compiler,\n pluginOptions: moduleFederationPlugin.ModuleFederationPluginOptions,\n options: any,\n) => {\n const match = findLoaderForResource(\n compiler.options.module.rules as RuleSetRule[],\n {\n path: path.join(compiler.context, '/something/thing.js'),\n issuerLayer: undefined,\n layer: undefined,\n },\n );\n\n compiler.options.module.rules.forEach((rule) => {\n if (typeof rule === 'object' && rule !== null) {\n const typedRule = rule as RuleSetRule;\n // next-image-loader fix which adds remote's hostname to the assets url\n if (\n options.enableImageLoaderFix &&\n hasLoader(typedRule, 'next-image-loader')\n ) {\n injectRuleLoader(typedRule, {\n loader: resolveFixImageLoaderPath(),\n });\n }\n\n if (options.enableUrlLoaderFix && hasLoader(typedRule, 'url-loader')) {\n injectRuleLoader(typedRule, {\n loader: resolveFixUrlLoaderPath(),\n });\n }\n }\n });\n\n if (match) {\n let matchCopy: RuleSetRule;\n if (match.use) {\n matchCopy = { ...match };\n if (Array.isArray(match.use)) {\n matchCopy.use = match.use.filter((loader: any) => {\n return (\n typeof loader === 'object' &&\n loader.loader &&\n !loader.loader.includes('react')\n );\n });\n } else if (typeof match.use === 'string') {\n matchCopy.use = match.use.includes('react') ? '' : match.use;\n } else if (typeof match.use === 'object' && match.use !== null) {\n matchCopy.use =\n match.use.loader && match.use.loader.includes('react')\n ? {}\n : match.use;\n }\n } else {\n matchCopy = { ...match };\n }\n\n const descriptionDataRule: RuleSetRule = {\n ...matchCopy,\n descriptionData: {\n name: /^(@module-federation)/,\n },\n exclude: undefined,\n include: undefined,\n };\n\n const testRule: RuleSetRule = {\n ...matchCopy,\n resourceQuery: /runtimePlugin/,\n exclude: undefined,\n include: undefined,\n };\n\n const oneOfRule = compiler.options.module.rules.find(\n (rule): rule is RuleSetRule => {\n return !!rule && typeof rule === 'object' && 'oneOf' in rule;\n },\n ) as RuleSetRule | undefined;\n\n if (!oneOfRule) {\n compiler.options.module.rules.unshift({\n oneOf: [descriptionDataRule, testRule],\n });\n } else if (oneOfRule.oneOf) {\n oneOfRule.oneOf.unshift(descriptionDataRule, testRule);\n }\n }\n};\n\nexport interface NextFederationPluginExtraOptions {\n enableImageLoaderFix?: boolean;\n enableUrlLoaderFix?: boolean;\n exposePages?: boolean;\n skipSharingNextInternals?: boolean;\n automaticPageStitching?: boolean;\n debug?: boolean;\n}\n\nexport interface NextFederationPluginOptions\n extends moduleFederationPlugin.ModuleFederationPluginOptions {\n extraOptions: NextFederationPluginExtraOptions;\n}\n"],"mappings":";;;;;;AAgBA,MAAM,4CAEQ,QACN,mEACD;AAKP,MAAM,0CAEQ,QACN,iEACD;;;;;;AASP,MAAa,yBACX,aACwC;AAGxC,KAAI,SACF,QAAO;AAGT,QAAO;;AAET,MAAa,kBACX,UACA,eACA,YACG;CACH,MAAM,QAAQ,sBACZ,SAAS,QAAQ,OAAO,OACxB;EACE,MAAM,KAAK,KAAK,SAAS,SAAS,sBAAsB;EACxD,aAAa;EACb,OAAO;EACR,CACF;AAED,UAAS,QAAQ,OAAO,MAAM,SAAS,SAAS;AAC9C,MAAI,OAAO,SAAS,YAAY,SAAS,MAAM;GAC7C,MAAM,YAAY;AAElB,OACE,QAAQ,wBACR,UAAU,WAAW,oBAAoB,CAEzC,kBAAiB,WAAW,EAC1B,QAAQ,2BAA2B,EACpC,CAAC;AAGJ,OAAI,QAAQ,sBAAsB,UAAU,WAAW,aAAa,CAClE,kBAAiB,WAAW,EAC1B,QAAQ,yBAAyB,EAClC,CAAC;;GAGN;AAEF,KAAI,OAAO;EACT,IAAI;AACJ,MAAI,MAAM,KAAK;AACb,eAAY,EAAE,GAAG,OAAO;AACxB,OAAI,MAAM,QAAQ,MAAM,IAAI,CAC1B,WAAU,MAAM,MAAM,IAAI,QAAQ,WAAgB;AAChD,WACE,OAAO,WAAW,YAClB,OAAO,UACP,CAAC,OAAO,OAAO,SAAS,QAAQ;KAElC;YACO,OAAO,MAAM,QAAQ,SAC9B,WAAU,MAAM,MAAM,IAAI,SAAS,QAAQ,GAAG,KAAK,MAAM;YAChD,OAAO,MAAM,QAAQ,YAAY,MAAM,QAAQ,KACxD,WAAU,MACR,MAAM,IAAI,UAAU,MAAM,IAAI,OAAO,SAAS,QAAQ,GAClD,EAAE,GACF,MAAM;QAGd,aAAY,EAAE,GAAG,OAAO;EAG1B,MAAM,sBAAmC;GACvC,GAAG;GACH,iBAAiB,EACf,MAAM,yBACP;GACD,SAAS;GACT,SAAS;GACV;EAED,MAAM,WAAwB;GAC5B,GAAG;GACH,eAAe;GACf,SAAS;GACT,SAAS;GACV;EAED,MAAM,YAAY,SAAS,QAAQ,OAAO,MAAM,MAC7C,SAA8B;AAC7B,UAAO,CAAC,CAAC,QAAQ,OAAO,SAAS,YAAY,WAAW;IAE3D;AAED,MAAI,CAAC,UACH,UAAS,QAAQ,OAAO,MAAM,QAAQ,EACpC,OAAO,CAAC,qBAAqB,SAAS,EACvC,CAAC;WACO,UAAU,MACnB,WAAU,MAAM,QAAQ,qBAAqB,SAAS"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
const require_runtime = require('../../../_virtual/_rolldown/runtime.js');
|
|
2
1
|
const require_InvertedContainerRuntimeModule = require('./InvertedContainerRuntimeModule.js');
|
|
3
|
-
let _module_federation_enhanced = require("@module-federation/enhanced");
|
|
4
|
-
_module_federation_enhanced = require_runtime.__toESM(_module_federation_enhanced);
|
|
5
2
|
|
|
6
3
|
//#region src/plugins/container/InvertedContainerPlugin.ts
|
|
7
|
-
const
|
|
4
|
+
const loadEnhanced = () => {
|
|
5
|
+
const enhancedModule = require("@module-federation/enhanced");
|
|
6
|
+
return enhancedModule.default ? enhancedModule.default : enhancedModule;
|
|
7
|
+
};
|
|
8
8
|
var InvertedContainerPlugin = class {
|
|
9
9
|
apply(compiler) {
|
|
10
|
+
const { FederationModulesPlugin, dependencies } = loadEnhanced();
|
|
10
11
|
compiler.hooks.thisCompilation.tap("EmbeddedContainerPlugin", (compilation) => {
|
|
11
12
|
const hooks = FederationModulesPlugin.getCompilationHooks(compilation);
|
|
12
13
|
const containers = /* @__PURE__ */ new Set();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InvertedContainerPlugin.js","names":["
|
|
1
|
+
{"version":3,"file":"InvertedContainerPlugin.js","names":["InvertedContainerRuntimeModule"],"sources":["../../../../src/plugins/container/InvertedContainerPlugin.ts"],"sourcesContent":["import type { Compilation, Compiler, Chunk } from 'webpack';\nimport InvertedContainerRuntimeModule from './InvertedContainerRuntimeModule';\n\ntype EnhancedModuleExports = typeof import('@module-federation/enhanced');\n\nconst loadEnhanced = (): EnhancedModuleExports => {\n const enhancedModule = require('@module-federation/enhanced') as\n | EnhancedModuleExports\n | { default: EnhancedModuleExports };\n\n return (enhancedModule as { default?: EnhancedModuleExports }).default\n ? (enhancedModule as { default: EnhancedModuleExports }).default\n : (enhancedModule as EnhancedModuleExports);\n};\n\nclass InvertedContainerPlugin {\n public apply(compiler: Compiler): void {\n const { FederationModulesPlugin, dependencies } = loadEnhanced();\n\n compiler.hooks.thisCompilation.tap(\n 'EmbeddedContainerPlugin',\n (compilation: Compilation) => {\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n const containers = new Set();\n hooks.addContainerEntryDependency.tap(\n 'EmbeddedContainerPlugin',\n (dependency) => {\n if (dependency instanceof dependencies.ContainerEntryDependency) {\n containers.add(dependency);\n }\n },\n );\n // Adding the runtime module\n compilation.hooks.additionalTreeRuntimeRequirements.tap(\n 'EmbeddedContainerPlugin',\n (chunk, set) => {\n compilation.addRuntimeModule(\n chunk,\n new InvertedContainerRuntimeModule({\n containers,\n }),\n );\n },\n );\n },\n );\n }\n}\n\nexport default InvertedContainerPlugin;\n"],"mappings":";;;AAKA,MAAM,qBAA4C;CAChD,MAAM,iBAAiB,QAAQ,8BAA8B;AAI7D,QAAQ,eAAuD,UAC1D,eAAsD,UACtD;;AAGP,IAAM,0BAAN,MAA8B;CAC5B,AAAO,MAAM,UAA0B;EACrC,MAAM,EAAE,yBAAyB,iBAAiB,cAAc;AAEhE,WAAS,MAAM,gBAAgB,IAC7B,4BACC,gBAA6B;GAC5B,MAAM,QAAQ,wBAAwB,oBAAoB,YAAY;GACtE,MAAM,6BAAa,IAAI,KAAK;AAC5B,SAAM,4BAA4B,IAChC,4BACC,eAAe;AACd,QAAI,sBAAsB,aAAa,yBACrC,YAAW,IAAI,WAAW;KAG/B;AAED,eAAY,MAAM,kCAAkC,IAClD,4BACC,OAAO,QAAQ;AACd,gBAAY,iBACV,OACA,IAAIA,+CAA+B,EACjC,YACD,CAAC,CACH;KAEJ;IAEJ"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { __require } from "../../../_virtual/_rolldown/runtime.mjs";
|
|
1
2
|
import InvertedContainerRuntimeModule from "./InvertedContainerRuntimeModule.mjs";
|
|
2
|
-
import * as enhancedModule from "@module-federation/enhanced";
|
|
3
3
|
|
|
4
4
|
//#region src/plugins/container/InvertedContainerPlugin.ts
|
|
5
|
-
const
|
|
5
|
+
const loadEnhanced = () => {
|
|
6
|
+
const enhancedModule = __require("@module-federation/enhanced");
|
|
7
|
+
return enhancedModule.default ? enhancedModule.default : enhancedModule;
|
|
8
|
+
};
|
|
6
9
|
var InvertedContainerPlugin = class {
|
|
7
10
|
apply(compiler) {
|
|
11
|
+
const { FederationModulesPlugin, dependencies } = loadEnhanced();
|
|
8
12
|
compiler.hooks.thisCompilation.tap("EmbeddedContainerPlugin", (compilation) => {
|
|
9
13
|
const hooks = FederationModulesPlugin.getCompilationHooks(compilation);
|
|
10
14
|
const containers = /* @__PURE__ */ new Set();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InvertedContainerPlugin.mjs","names":[],"sources":["../../../../src/plugins/container/InvertedContainerPlugin.ts"],"sourcesContent":["import type { Compilation, Compiler, Chunk } from 'webpack';\nimport InvertedContainerRuntimeModule from './InvertedContainerRuntimeModule';\
|
|
1
|
+
{"version":3,"file":"InvertedContainerPlugin.mjs","names":[],"sources":["../../../../src/plugins/container/InvertedContainerPlugin.ts"],"sourcesContent":["import type { Compilation, Compiler, Chunk } from 'webpack';\nimport InvertedContainerRuntimeModule from './InvertedContainerRuntimeModule';\n\ntype EnhancedModuleExports = typeof import('@module-federation/enhanced');\n\nconst loadEnhanced = (): EnhancedModuleExports => {\n const enhancedModule = require('@module-federation/enhanced') as\n | EnhancedModuleExports\n | { default: EnhancedModuleExports };\n\n return (enhancedModule as { default?: EnhancedModuleExports }).default\n ? (enhancedModule as { default: EnhancedModuleExports }).default\n : (enhancedModule as EnhancedModuleExports);\n};\n\nclass InvertedContainerPlugin {\n public apply(compiler: Compiler): void {\n const { FederationModulesPlugin, dependencies } = loadEnhanced();\n\n compiler.hooks.thisCompilation.tap(\n 'EmbeddedContainerPlugin',\n (compilation: Compilation) => {\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n const containers = new Set();\n hooks.addContainerEntryDependency.tap(\n 'EmbeddedContainerPlugin',\n (dependency) => {\n if (dependency instanceof dependencies.ContainerEntryDependency) {\n containers.add(dependency);\n }\n },\n );\n // Adding the runtime module\n compilation.hooks.additionalTreeRuntimeRequirements.tap(\n 'EmbeddedContainerPlugin',\n (chunk, set) => {\n compilation.addRuntimeModule(\n chunk,\n new InvertedContainerRuntimeModule({\n containers,\n }),\n );\n },\n );\n },\n );\n }\n}\n\nexport default InvertedContainerPlugin;\n"],"mappings":";;;;AAKA,MAAM,qBAA4C;CAChD,MAAM,2BAAyB,8BAA8B;AAI7D,QAAQ,eAAuD,UAC1D,eAAsD,UACtD;;AAGP,IAAM,0BAAN,MAA8B;CAC5B,AAAO,MAAM,UAA0B;EACrC,MAAM,EAAE,yBAAyB,iBAAiB,cAAc;AAEhE,WAAS,MAAM,gBAAgB,IAC7B,4BACC,gBAA6B;GAC5B,MAAM,QAAQ,wBAAwB,oBAAoB,YAAY;GACtE,MAAM,6BAAa,IAAI,KAAK;AAC5B,SAAM,4BAA4B,IAChC,4BACC,eAAe;AACd,QAAI,sBAAsB,aAAa,yBACrC,YAAW,IAAI,WAAW;KAG/B;AAED,eAAY,MAAM,kCAAkC,IAClD,4BACC,OAAO,QAAQ;AACd,gBAAY,iBACV,OACA,IAAI,+BAA+B,EACjC,YACD,CAAC,CACH;KAEJ;IAEJ"}
|
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.58",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"module": "dist/src/index.mjs",
|
|
@@ -58,11 +58,11 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"fast-glob": "^3.2.11",
|
|
61
|
-
"@module-federation/
|
|
62
|
-
"@module-federation/
|
|
63
|
-
"@module-federation/
|
|
64
|
-
"@module-federation/
|
|
65
|
-
"@module-federation/
|
|
61
|
+
"@module-federation/runtime": "2.2.0",
|
|
62
|
+
"@module-federation/enhanced": "2.2.0",
|
|
63
|
+
"@module-federation/node": "2.7.34",
|
|
64
|
+
"@module-federation/webpack-bundler-runtime": "2.2.0",
|
|
65
|
+
"@module-federation/sdk": "2.2.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@types/btoa": "^1.2.5",
|
|
@@ -95,6 +95,10 @@
|
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
97
|
"scripts": {
|
|
98
|
-
"postinstall": "echo \"Deprecation Notice: We intend to deprecate 'nextjs-mf'. Please see https://github.com/module-federation/core/issues/3153 for more details.\""
|
|
98
|
+
"postinstall": "echo \"Deprecation Notice: We intend to deprecate 'nextjs-mf'. Please see https://github.com/module-federation/core/issues/3153 for more details.\"",
|
|
99
|
+
"build": "tsdown --config tsdown.config.mts",
|
|
100
|
+
"lint": "ESLINT_USE_FLAT_CONFIG=false pnpm exec eslint --ignore-pattern node_modules \"**/*.js\" \"**/*.ts\"",
|
|
101
|
+
"test": "pnpm exec jest --config jest.config.js --passWithNoTests",
|
|
102
|
+
"pre-release": "pnpm run test && pnpm run build && rm -f ./dist/package.json"
|
|
99
103
|
}
|
|
100
104
|
}
|