@module-federation/nextjs-mf 6.4.0 → 6.4.1-beta.1
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/CHANGELOG.md +111 -0
- package/README.md +3 -0
- package/package.json +4 -4
- package/src/default-delegate.d.ts +2 -0
- package/src/default-delegate.js +17 -0
- package/src/default-delegate.js.map +1 -0
- package/src/delegate-hoist-container.d.ts +0 -0
- package/src/delegate-hoist-container.js +2 -0
- package/src/delegate-hoist-container.js.map +1 -0
- package/src/index.d.ts +1 -1
- package/src/index.js +6 -5
- package/src/index.js.map +1 -1
- package/src/internal-delegate-hoist.js +1 -0
- package/src/internal-delegate-hoist.js.map +1 -1
- package/src/internal.d.ts +39 -9
- package/src/internal.js +149 -235
- package/src/internal.js.map +1 -1
- package/src/inverse-self-formation.d.ts +0 -0
- package/src/inverse-self-formation.js +2 -0
- package/src/inverse-self-formation.js.map +1 -0
- package/src/loaders/async-boundary-loader.js +10 -2
- package/src/loaders/async-boundary-loader.js.map +1 -1
- package/src/loaders/delegateLoader.js +2 -4
- package/src/loaders/delegateLoader.js.map +1 -1
- package/src/loaders/inject-hoist.d.ts +3 -0
- package/src/loaders/inject-hoist.js +8 -0
- package/src/loaders/inject-hoist.js.map +1 -0
- package/src/loaders/nextPageMapLoader.js +0 -2
- package/src/loaders/nextPageMapLoader.js.map +1 -1
- package/src/loaders/share-scope-hoist.d.ts +5 -0
- package/src/loaders/share-scope-hoist.js +52 -0
- package/src/loaders/share-scope-hoist.js.map +1 -0
- package/src/plugins/AddModulesToRuntime.d.ts +19 -0
- package/src/plugins/AddModulesToRuntime.js +268 -0
- package/src/plugins/AddModulesToRuntime.js.map +1 -0
- package/src/plugins/ContainerStatsPlugin.d.ts +6 -0
- package/src/plugins/ContainerStatsPlugin.js +176 -0
- package/src/plugins/ContainerStatsPlugin.js.map +1 -0
- package/src/plugins/CopyFederationPlugin.d.ts +7 -0
- package/src/plugins/CopyFederationPlugin.js +48 -0
- package/src/plugins/CopyFederationPlugin.js.map +1 -0
- package/src/plugins/NextFederationPlugin/apply-automatic-async-boundary.d.ts +11 -0
- package/src/plugins/NextFederationPlugin/apply-automatic-async-boundary.js +61 -0
- package/src/plugins/NextFederationPlugin/apply-automatic-async-boundary.js.map +1 -0
- package/src/plugins/NextFederationPlugin/apply-client-plugins.d.ts +24 -0
- package/src/plugins/NextFederationPlugin/apply-client-plugins.js +79 -0
- package/src/plugins/NextFederationPlugin/apply-client-plugins.js.map +1 -0
- package/src/plugins/NextFederationPlugin/apply-server-plugins.d.ts +61 -0
- package/src/plugins/NextFederationPlugin/apply-server-plugins.js +158 -0
- package/src/plugins/NextFederationPlugin/apply-server-plugins.js.map +1 -0
- package/src/plugins/NextFederationPlugin/index.d.ts +18 -0
- package/src/plugins/NextFederationPlugin/index.js +133 -0
- package/src/plugins/NextFederationPlugin/index.js.map +1 -0
- package/src/plugins/NextFederationPlugin/next-fragments.d.ts +44 -0
- package/src/plugins/NextFederationPlugin/next-fragments.js +115 -0
- package/src/plugins/NextFederationPlugin/next-fragments.js.map +1 -0
- package/src/plugins/NextFederationPlugin/regex-equal.d.ts +14 -0
- package/src/plugins/NextFederationPlugin/regex-equal.js +25 -0
- package/src/plugins/NextFederationPlugin/regex-equal.js.map +1 -0
- package/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.d.ts +1 -0
- package/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js +20 -0
- package/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js.map +1 -0
- package/src/plugins/NextFederationPlugin/set-options.d.ts +21 -0
- package/src/plugins/NextFederationPlugin/set-options.js +35 -0
- package/src/plugins/NextFederationPlugin/set-options.js.map +1 -0
- package/src/plugins/NextFederationPlugin/validate-options.d.ts +26 -0
- package/src/plugins/NextFederationPlugin/validate-options.js +46 -0
- package/src/plugins/NextFederationPlugin/validate-options.js.map +1 -0
- package/src/plugins/async-pages-loader.d.ts +1 -0
- package/src/plugins/async-pages-loader.js +41 -0
- package/src/plugins/async-pages-loader.js.map +1 -0
- package/src/plugins/container/InvertedContainerPlugin.d.ts +25 -0
- package/src/plugins/container/InvertedContainerPlugin.js +73 -0
- package/src/plugins/container/InvertedContainerPlugin.js.map +1 -0
- package/src/plugins/container/InvertedContainerRuntimeModule.d.ts +42 -0
- package/src/plugins/container/InvertedContainerRuntimeModule.js +82 -0
- package/src/plugins/container/InvertedContainerRuntimeModule.js.map +1 -0
- package/src/plugins/container/types.d.ts +2 -0
- package/src/plugins/container/types.js +3 -0
- package/src/plugins/container/types.js.map +1 -0
- package/utils/Template.d.ts +1 -1
- package/utils/Template.js +1 -1
- package/utils/Template.js.map +1 -1
- package/utils/build-utils.d.ts +0 -8
- package/utils/build-utils.js +1 -228
- package/utils/build-utils.js.map +1 -1
- package/utils/index.d.ts +2 -2
- package/utils/index.js +8 -2
- package/utils/index.js.map +1 -1
- package/src/plugins/ChildFederationPlugin.d.ts +0 -11
- package/src/plugins/ChildFederationPlugin.js +0 -299
- package/src/plugins/ChildFederationPlugin.js.map +0 -1
- package/src/plugins/ModuleFederationPlugin.d.ts +0 -7
- package/src/plugins/ModuleFederationPlugin.js +0 -50
- package/src/plugins/ModuleFederationPlugin.js.map +0 -1
- package/src/plugins/NextFederationPlugin.d.ts +0 -9
- package/src/plugins/NextFederationPlugin.js +0 -234
- package/src/plugins/NextFederationPlugin.js.map +0 -1
- package/src/plugins/RemoveRRRuntimePlugin.d.ts +0 -5
- package/src/plugins/RemoveRRRuntimePlugin.js +0 -40
- package/src/plugins/RemoveRRRuntimePlugin.js.map +0 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyRemoteDelegates = exports.injectModuleHoistingSystem = exports.retrieveDefaultShared = exports.getModuleFederationPluginConstructor = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
6
|
+
const internal_1 = require("../../internal");
|
|
7
|
+
/**
|
|
8
|
+
* Gets the appropriate ModuleFederationPlugin based on the environment.
|
|
9
|
+
* @param {boolean} isServer - A flag to indicate if the environment is server-side or not.
|
|
10
|
+
* @param {Compiler} compiler - The Webpack compiler instance.
|
|
11
|
+
* @returns {ModuleFederationPlugin | undefined} The ModuleFederationPlugin or undefined if not applicable.
|
|
12
|
+
*/
|
|
13
|
+
function getModuleFederationPluginConstructor(isServer, compiler) {
|
|
14
|
+
if (isServer) {
|
|
15
|
+
return require('@module-federation/node')
|
|
16
|
+
.NodeFederationPlugin;
|
|
17
|
+
}
|
|
18
|
+
return compiler.webpack.container
|
|
19
|
+
.ModuleFederationPlugin;
|
|
20
|
+
}
|
|
21
|
+
exports.getModuleFederationPluginConstructor = getModuleFederationPluginConstructor;
|
|
22
|
+
/**
|
|
23
|
+
|
|
24
|
+
Set up default shared values based on the environment.
|
|
25
|
+
@param isServer - Boolean indicating if the code is running on the server.
|
|
26
|
+
@returns The default share scope based on the environment.
|
|
27
|
+
*/
|
|
28
|
+
const retrieveDefaultShared = (isServer) => {
|
|
29
|
+
// If the code is running on the server, treat some Next.js internals as import false to make them external
|
|
30
|
+
// This is because they will be provided by the server environment and not by the remote container
|
|
31
|
+
if (isServer) {
|
|
32
|
+
return internal_1.DEFAULT_SHARE_SCOPE;
|
|
33
|
+
}
|
|
34
|
+
// If the code is running on the client/browser, always bundle Next.js internals
|
|
35
|
+
return internal_1.DEFAULT_SHARE_SCOPE_BROWSER;
|
|
36
|
+
};
|
|
37
|
+
exports.retrieveDefaultShared = retrieveDefaultShared;
|
|
38
|
+
/**
|
|
39
|
+
|
|
40
|
+
Inject module hoisting system.
|
|
41
|
+
This function injects the module hoisting system into the webpack build process. The module hoisting system is a way to
|
|
42
|
+
optimize the build process by hoisting dependencies into specific files that are hoisted into the webpack runtimes. This
|
|
43
|
+
function is used by the NextFederationPlugin to optimize the build process when using module federation with Next.js.
|
|
44
|
+
@param {boolean} isServer - A boolean indicating whether the code is running on the server.
|
|
45
|
+
@param {ModuleFederationPluginOptions} options - The options for the ModuleFederationPlugin.
|
|
46
|
+
@param {Compiler} compiler - The webpack compiler instance.
|
|
47
|
+
*/
|
|
48
|
+
function injectModuleHoistingSystem(isServer, options, compiler) {
|
|
49
|
+
// Set the default shared values based on the environment
|
|
50
|
+
const defaultShared = (0, exports.retrieveDefaultShared)(isServer);
|
|
51
|
+
// Inject hoist dependency into the upper scope of the application
|
|
52
|
+
const injectHoistDependency = {
|
|
53
|
+
enforce: 'pre',
|
|
54
|
+
test: /_document/,
|
|
55
|
+
include: [compiler.context, /next\/dist/],
|
|
56
|
+
loader: path_1.default.resolve(__dirname, '../../loaders/inject-hoist'),
|
|
57
|
+
};
|
|
58
|
+
// Populate hoist dependency with shared modules
|
|
59
|
+
const populateHoistDependency = {
|
|
60
|
+
test: /internal-delegate-hoist/,
|
|
61
|
+
include: [/internal-delegate-hoist/, compiler.context, /next\/dist/],
|
|
62
|
+
loader: path_1.default.resolve(__dirname, '../../loaders/share-scope-hoist'),
|
|
63
|
+
options: {
|
|
64
|
+
shared: defaultShared,
|
|
65
|
+
name: !isServer && options.name,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
// Unshift the injectHoistDependency and populateHoistDependency to the front of the module.rules array
|
|
69
|
+
compiler.options.module.rules.unshift(
|
|
70
|
+
//@ts-ignore
|
|
71
|
+
injectHoistDependency, populateHoistDependency);
|
|
72
|
+
// The module hoisting system is a way to optimize the build process by hoisting dependencies into specific files that
|
|
73
|
+
// are hoisted into the webpack runtimes. This function is used by the NextFederationPlugin to optimize the build process
|
|
74
|
+
// when using module federation with Next.js. The function takes a boolean isServer, which is used to set the default
|
|
75
|
+
// shared values based on the environment. The options argument is an object with options for the ModuleFederationPlugin.
|
|
76
|
+
// The compiler argument is the webpack compiler instance.
|
|
77
|
+
}
|
|
78
|
+
exports.injectModuleHoistingSystem = injectModuleHoistingSystem;
|
|
79
|
+
/**
|
|
80
|
+
|
|
81
|
+
Apply remote delegates.
|
|
82
|
+
|
|
83
|
+
This function adds the remote delegates feature by configuring and injecting the appropriate loader that will look
|
|
84
|
+
for internal delegate hoist or delegate hoist container and load it using a custom delegateLoader.
|
|
85
|
+
Once loaded, it will then look for the available delegates that will be used to configure the remote
|
|
86
|
+
that the hoisted module will be dependent upon.
|
|
87
|
+
|
|
88
|
+
@param {ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
|
|
89
|
+
|
|
90
|
+
@param {Compiler} compiler - The Webpack compiler instance.
|
|
91
|
+
*/
|
|
92
|
+
function applyRemoteDelegates(options, compiler) {
|
|
93
|
+
if (options.remotes) {
|
|
94
|
+
// Get the available delegates
|
|
95
|
+
const delegates = (0, internal_1.getDelegates)(options.remotes);
|
|
96
|
+
// Add the delegate loader for hoist and container to the module rules
|
|
97
|
+
compiler.options.module.rules.push({
|
|
98
|
+
enforce: 'pre',
|
|
99
|
+
test: [/internal-delegate-hoist/, /delegate-hoist-container/],
|
|
100
|
+
include: [
|
|
101
|
+
compiler.context,
|
|
102
|
+
/internal-delegate-hoist/,
|
|
103
|
+
/delegate-hoist-container/,
|
|
104
|
+
//eslint-disable-next-line
|
|
105
|
+
/next[\/]dist/,
|
|
106
|
+
],
|
|
107
|
+
loader: path_1.default.resolve(__dirname, '../../loaders/delegateLoader'),
|
|
108
|
+
options: {
|
|
109
|
+
delegates,
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.applyRemoteDelegates = applyRemoteDelegates;
|
|
115
|
+
//# sourceMappingURL=next-fragments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-fragments.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/NextFederationPlugin/next-fragments.ts"],"names":[],"mappings":";;;;AAEA,wDAAwB;AAKxB,6CAIwB;AAMxB;;;;;GAKG;AACH,SAAgB,oCAAoC,CAClD,QA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O;IACnC,YAAY;IACZ,qBAAqB,EACrB,uBAAuB,CACxB,CAAC;IAEF,sHAAsH;IACtH,yHAAyH;IACzH,qHAAqH;IACrH,yHAAyH;IACzH,0DAA0D;AAC5D,CAAC;AAtCD,gEAsCC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,oBAAoB,CAClC,OAAsC,EACtC,QAAkB;IAElB,IAAI,OAAO,CAAC,OAAO,EAAE;QACnB,8BAA8B;QAC9B,MAAM,SAAS,GAAG,IAAA,uBAAY,EAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAEhD,sEAAsE;QACtE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;YACjC,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,CAAC,yBAAyB,EAAE,0BAA0B,CAAC;YAC7D,OAAO,EAAE;gBACP,QAAQ,CAAC,OAAO;gBAChB,yBAAyB;gBACzB,0BAA0B;gBAC1B,0BAA0B;gBAC1B,cAAc;aACf;YACD,MAAM,EAAE,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,8BAA8B,CAAC;YAC/D,OAAO,EAAE;gBACP,SAAS;aACV;SACF,CAAC,CAAC;KACJ;AACH,CAAC;AAzBD,oDAyBC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RuleSetConditionAbsolute } from "webpack";
|
|
2
|
+
/**
|
|
3
|
+
* Compares two regular expressions to see if they are equal.
|
|
4
|
+
*
|
|
5
|
+
* @param x - The first regular expression to compare.
|
|
6
|
+
* @param y - The second regular expression to compare.
|
|
7
|
+
* @returns True if the regular expressions are equal, false otherwise.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This function compares two regular expressions to see if they are equal in terms of their source,
|
|
11
|
+
* global, ignoreCase, and multiline properties. It is used to check if two regular expressions match
|
|
12
|
+
* the same pattern.
|
|
13
|
+
*/
|
|
14
|
+
export declare const regexEqual: (x: string | RegExp | RuleSetConditionAbsolute[] | ((value: string) => boolean) | undefined, y: RegExp) => boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.regexEqual = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Compares two regular expressions to see if they are equal.
|
|
6
|
+
*
|
|
7
|
+
* @param x - The first regular expression to compare.
|
|
8
|
+
* @param y - The second regular expression to compare.
|
|
9
|
+
* @returns True if the regular expressions are equal, false otherwise.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* This function compares two regular expressions to see if they are equal in terms of their source,
|
|
13
|
+
* global, ignoreCase, and multiline properties. It is used to check if two regular expressions match
|
|
14
|
+
* the same pattern.
|
|
15
|
+
*/
|
|
16
|
+
const regexEqual = (x, y) => {
|
|
17
|
+
return (x instanceof RegExp &&
|
|
18
|
+
y instanceof RegExp &&
|
|
19
|
+
x.source === y.source &&
|
|
20
|
+
x.global === y.global &&
|
|
21
|
+
x.ignoreCase === y.ignoreCase &&
|
|
22
|
+
x.multiline === y.multiline);
|
|
23
|
+
};
|
|
24
|
+
exports.regexEqual = regexEqual;
|
|
25
|
+
//# sourceMappingURL=regex-equal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regex-equal.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/NextFederationPlugin/regex-equal.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;GAWG;AACI,MAAM,UAAU,GAAG,CACxB,CAKa,EACb,CAAS,EACA,EAAE;IACX,OAAO,CACL,CAAC,YAAY,MAAM;QACnB,CAAC,YAAY,MAAM;QACnB,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QACrB,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QACrB,CAAC,CAAC,UAAU,KAAK,CAAC,CAAC,UAAU;QAC7B,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS,CAC5B,CAAC;AACJ,CAAC,CAAC;AAjBW,QAAA,UAAU,cAiBrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function removeUnnecessarySharedKeys(shared: Record<string, unknown>): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeUnnecessarySharedKeys = void 0;
|
|
4
|
+
// Utility function to remove unnecessary shared keys from the default share scope
|
|
5
|
+
const internal_1 = require("../../internal");
|
|
6
|
+
function removeUnnecessarySharedKeys(shared) {
|
|
7
|
+
const warnings = Object.keys(shared).reduce((acc, key) => {
|
|
8
|
+
if (internal_1.DEFAULT_SHARE_SCOPE[key]) {
|
|
9
|
+
acc.push(`[nextjs-mf] You are sharing ${key} from the default share scope. This is not necessary and can be removed.`);
|
|
10
|
+
// Use a type assertion to inform TypeScript that 'key' can be used as an index for the 'shared' object
|
|
11
|
+
delete shared[key];
|
|
12
|
+
}
|
|
13
|
+
return acc;
|
|
14
|
+
}, []);
|
|
15
|
+
if (warnings.length > 0) {
|
|
16
|
+
console.warn('%c' + warnings.join('\n'), 'color: red');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.removeUnnecessarySharedKeys = removeUnnecessarySharedKeys;
|
|
20
|
+
//# sourceMappingURL=remove-unnecessary-shared-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-unnecessary-shared-keys.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.ts"],"names":[],"mappings":";;;AAAA,kFAAkF;AAClF,6CAAqD;AAErD,SAAgB,2BAA2B,CACzC,MAA+B;IAE/B,MAAM,QAAQ,GAAa,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CACnD,CAAC,GAAa,EAAE,GAAW,EAAE,EAAE;QAC7B,IAAI,8BAAmB,CAAC,GAAG,CAAC,EAAE;YAC5B,GAAG,CAAC,IAAI,CACN,+BAA+B,GAAG,0EAA0E,CAC7G,CAAC;YACF,uGAAuG;YACvG,OAAQ,MAAqC,CAAC,GAAG,CAAC,CAAC;SACpD;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAE,CACH,CAAC;IAEF,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;QACvB,OAAO,CAAC,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC,CAAC;KACxD;AACH,CAAC;AApBD,kEAoBC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ModuleFederationPluginOptions, NextFederationPluginExtraOptions, NextFederationPluginOptions } from "@module-federation/utilities";
|
|
2
|
+
/**
|
|
3
|
+
* Utility function to set the main and extra options.
|
|
4
|
+
*
|
|
5
|
+
* @param options - The NextFederationPluginOptions instance.
|
|
6
|
+
* @returns An object containing the main options and extra options.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* This function sets the main and extra options for NextFederationPlugin. It splits the options object into
|
|
10
|
+
* the main options and extra options, and sets default values for any options that are not defined. The default
|
|
11
|
+
* extra options are:
|
|
12
|
+
* - automaticPageStitching: false
|
|
13
|
+
* - enableImageLoaderFix: false
|
|
14
|
+
* - enableUrlLoaderFix: false
|
|
15
|
+
* - skipSharingNextInternals: false
|
|
16
|
+
* - automaticAsyncBoundary: false
|
|
17
|
+
*/
|
|
18
|
+
export declare function setOptions(options: NextFederationPluginOptions): {
|
|
19
|
+
mainOptions: ModuleFederationPluginOptions;
|
|
20
|
+
extraOptions: NextFederationPluginExtraOptions;
|
|
21
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setOptions = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Utility function to set the main and extra options.
|
|
6
|
+
*
|
|
7
|
+
* @param options - The NextFederationPluginOptions instance.
|
|
8
|
+
* @returns An object containing the main options and extra options.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* This function sets the main and extra options for NextFederationPlugin. It splits the options object into
|
|
12
|
+
* the main options and extra options, and sets default values for any options that are not defined. The default
|
|
13
|
+
* extra options are:
|
|
14
|
+
* - automaticPageStitching: false
|
|
15
|
+
* - enableImageLoaderFix: false
|
|
16
|
+
* - enableUrlLoaderFix: false
|
|
17
|
+
* - skipSharingNextInternals: false
|
|
18
|
+
* - automaticAsyncBoundary: false
|
|
19
|
+
*/
|
|
20
|
+
function setOptions(options) {
|
|
21
|
+
const { extraOptions, ...mainOpts } = options;
|
|
22
|
+
const defaultExtraOptions = {
|
|
23
|
+
automaticPageStitching: false,
|
|
24
|
+
enableImageLoaderFix: false,
|
|
25
|
+
enableUrlLoaderFix: false,
|
|
26
|
+
skipSharingNextInternals: false,
|
|
27
|
+
automaticAsyncBoundary: false
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
mainOptions: mainOpts,
|
|
31
|
+
extraOptions: { ...defaultExtraOptions, ...extraOptions }
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
exports.setOptions = setOptions;
|
|
35
|
+
//# sourceMappingURL=set-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-options.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/NextFederationPlugin/set-options.ts"],"names":[],"mappings":";;;AAMA;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,UAAU,CAAC,OAAoC;IAI7D,MAAM,EAAE,YAAY,EAAE,GAAG,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE9C,MAAM,mBAAmB,GAAqC;QAC5D,sBAAsB,EAAE,KAAK;QAC7B,oBAAoB,EAAE,KAAK;QAC3B,kBAAkB,EAAE,KAAK;QACzB,wBAAwB,EAAE,KAAK;QAC/B,sBAAsB,EAAE,KAAK;KAC9B,CAAC;IAEF,OAAO;QACL,WAAW,EAAE,QAAQ;QACrB,YAAY,EAAE,EAAE,GAAG,mBAAmB,EAAE,GAAG,YAAY,EAAE;KAC1D,CAAC;AACJ,CAAC;AAlBD,gCAkBC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Compiler } from "webpack";
|
|
2
|
+
import { ModuleFederationPluginOptions } from "@module-federation/utilities";
|
|
3
|
+
/**
|
|
4
|
+
* Utility function to validate compiler options.
|
|
5
|
+
*
|
|
6
|
+
* @param compiler - The Webpack compiler instance.
|
|
7
|
+
* @returns True if the compiler options are valid, false otherwise.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This function validates the options passed to the Webpack compiler. It throws an error if the name
|
|
11
|
+
* option is not defined in the options. It also checks if the name option is set to either "server" or
|
|
12
|
+
* "client", as Module Federation is only applied to the main server and client builds in Next.js.
|
|
13
|
+
*/
|
|
14
|
+
export declare function validateCompilerOptions(compiler: Compiler): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Utility function to validate NextFederationPlugin options.
|
|
17
|
+
*
|
|
18
|
+
* @param options - The ModuleFederationPluginOptions instance.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* This function validates the options passed to NextFederationPlugin. It throws an error if the filename
|
|
22
|
+
* option is not defined in the options.
|
|
23
|
+
*
|
|
24
|
+
* A requirement for using Module Federation is that a name must be specified.
|
|
25
|
+
*/
|
|
26
|
+
export declare function validatePluginOptions(options: ModuleFederationPluginOptions): void;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validatePluginOptions = exports.validateCompilerOptions = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Utility function to validate compiler options.
|
|
6
|
+
*
|
|
7
|
+
* @param compiler - The Webpack compiler instance.
|
|
8
|
+
* @returns True if the compiler options are valid, false otherwise.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* This function validates the options passed to the Webpack compiler. It throws an error if the name
|
|
12
|
+
* option is not defined in the options. It also checks if the name option is set to either "server" or
|
|
13
|
+
* "client", as Module Federation is only applied to the main server and client builds in Next.js.
|
|
14
|
+
*/
|
|
15
|
+
function validateCompilerOptions(compiler) {
|
|
16
|
+
// Throw an error if the name option is not defined in the options
|
|
17
|
+
if (!compiler.options.name) {
|
|
18
|
+
throw new Error("name is not defined in Compiler options");
|
|
19
|
+
}
|
|
20
|
+
// Only apply Module Federation to the main server and client builds in Next.js
|
|
21
|
+
return ["server", "client"].includes(compiler.options.name);
|
|
22
|
+
}
|
|
23
|
+
exports.validateCompilerOptions = validateCompilerOptions;
|
|
24
|
+
/**
|
|
25
|
+
* Utility function to validate NextFederationPlugin options.
|
|
26
|
+
*
|
|
27
|
+
* @param options - The ModuleFederationPluginOptions instance.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* This function validates the options passed to NextFederationPlugin. It throws an error if the filename
|
|
31
|
+
* option is not defined in the options.
|
|
32
|
+
*
|
|
33
|
+
* A requirement for using Module Federation is that a name must be specified.
|
|
34
|
+
*/
|
|
35
|
+
function validatePluginOptions(options) {
|
|
36
|
+
// Throw an error if the filename option is not defined in the options
|
|
37
|
+
if (!options.filename) {
|
|
38
|
+
throw new Error("filename is not defined in NextFederation options");
|
|
39
|
+
}
|
|
40
|
+
// A requirement for using Module Federation is that a name must be specified
|
|
41
|
+
if (!options.name) {
|
|
42
|
+
throw new Error("Module federation \"name\" option must be specified");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.validatePluginOptions = validatePluginOptions;
|
|
46
|
+
//# sourceMappingURL=validate-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-options.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/NextFederationPlugin/validate-options.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;;;GAUG;AACH,SAAgB,uBAAuB,CAAC,QAAkB;IACxD,kEAAkE;IAClE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;KAC5D;IAED,+EAA+E;IAC/E,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC9D,CAAC;AARD,0DAQC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,qBAAqB,CACnC,OAAsC;IAEtC,sEAAsE;IACtE,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;KACtE;IAED,6EAA6E;IAC7E,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;KACxE;AACH,CAAC;AAZD,sDAYC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* Requires either the default delegate module or a custom one
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
module.exports = function patchDefaultSharedLoader(content) {
|
|
9
|
+
const isRouter = this.remainingRequest.includes('router.js');
|
|
10
|
+
// console.log(this.remainingRequest);
|
|
11
|
+
if (content.includes('hasMerkersOfInj')) {
|
|
12
|
+
return content;
|
|
13
|
+
}
|
|
14
|
+
return `
|
|
15
|
+
//hasMerkersOfInj
|
|
16
|
+
await import('react');
|
|
17
|
+
export default await import(${JSON.stringify(this.remainingRequest)});`;
|
|
18
|
+
return `
|
|
19
|
+
//hasMerkersOfInj
|
|
20
|
+
module.exports = Promise.resolve(window._N_E).then((router)=>{
|
|
21
|
+
if(!window.next && router.default){
|
|
22
|
+
console.log(window.next);
|
|
23
|
+
window.next.router = router
|
|
24
|
+
}
|
|
25
|
+
console.log('resolving router', window._N_E, router);
|
|
26
|
+
|
|
27
|
+
return import(${JSON.stringify(this.remainingRequest)}).then((mod) => {
|
|
28
|
+
console.log('mounting router', window._N_E, module.id);
|
|
29
|
+
|
|
30
|
+
return mod.default || mod;
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
`;
|
|
34
|
+
return `Promise.resolve(__webpack_init_sharing__('default')).then(async ()=>{
|
|
35
|
+
await import('react');
|
|
36
|
+
console.log('loading react before pushing page callback');
|
|
37
|
+
${content}
|
|
38
|
+
})`;
|
|
39
|
+
return content;
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=async-pages-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-pages-loader.js","sourceRoot":"","sources":["../../../../../packages/nextjs-mf/src/plugins/async-pages-loader.ts"],"names":[],"mappings":";;AACA;;;;GAIG;AACH,MAAM,CAAC,OAAO,GAAG,SAAS,wBAAwB,CAEhD,OAAe;IAEf,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC7D,sCAAsC;IACtC,IAAI,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE;QACvC,OAAO,OAAO,CAAC;KAChB;IAED,OAAO;;;8BAGqB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;IAEtE,OAAO;;;;;;;;;kBASS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC;;;;;;GAMpD,CAAC;IAEF,OAAO;;;IAGL,OAAO;KACN,CAAC;IAEJ,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Compilation, Compiler } from 'webpack';
|
|
2
|
+
/**
|
|
3
|
+
* InvertedContainerPlugin is a Webpack plugin that handles loading of chunks in a federated module.
|
|
4
|
+
* It sets up runtime modules for each chunk, ensuring the proper loading of remote modules.
|
|
5
|
+
*/
|
|
6
|
+
declare class InvertedContainerPlugin {
|
|
7
|
+
private options;
|
|
8
|
+
/**
|
|
9
|
+
* Constructor for the InvertedContainerPlugin.
|
|
10
|
+
* @param {InvertedContainerOptions} options - Plugin configuration options.
|
|
11
|
+
*/
|
|
12
|
+
constructor(options: {
|
|
13
|
+
container: string | undefined;
|
|
14
|
+
runtime: string;
|
|
15
|
+
remotes: Record<string, string>;
|
|
16
|
+
debug: boolean;
|
|
17
|
+
});
|
|
18
|
+
resolveContainerModule(compilation: Compilation): import("webpack").Module | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Apply method for the Webpack plugin, handling the plugin logic and hooks.
|
|
21
|
+
* @param {Compiler} compiler - Webpack compiler instance.
|
|
22
|
+
*/
|
|
23
|
+
apply(compiler: Compiler): void;
|
|
24
|
+
}
|
|
25
|
+
export default InvertedContainerPlugin;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const InvertedContainerRuntimeModule_1 = tslib_1.__importDefault(require("./InvertedContainerRuntimeModule"));
|
|
5
|
+
/**
|
|
6
|
+
* InvertedContainerPlugin is a Webpack plugin that handles loading of chunks in a federated module.
|
|
7
|
+
* It sets up runtime modules for each chunk, ensuring the proper loading of remote modules.
|
|
8
|
+
*/
|
|
9
|
+
class InvertedContainerPlugin {
|
|
10
|
+
/**
|
|
11
|
+
* Constructor for the InvertedContainerPlugin.
|
|
12
|
+
* @param {InvertedContainerOptions} options - Plugin configuration options.
|
|
13
|
+
*/
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.options = options || {};
|
|
16
|
+
}
|
|
17
|
+
resolveContainerModule(compilation) {
|
|
18
|
+
if (!this.options.container) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const container = compilation.entrypoints
|
|
22
|
+
.get(this.options.container)
|
|
23
|
+
?.getRuntimeChunk?.();
|
|
24
|
+
const entryModule = container?.entryModule;
|
|
25
|
+
return entryModule;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Apply method for the Webpack plugin, handling the plugin logic and hooks.
|
|
29
|
+
* @param {Compiler} compiler - Webpack compiler instance.
|
|
30
|
+
*/
|
|
31
|
+
apply(compiler) {
|
|
32
|
+
// Hook into the compilation process.
|
|
33
|
+
compiler.hooks.thisCompilation.tap('InvertedContainerPlugin', (compilation) => {
|
|
34
|
+
// Create a WeakSet to store chunks that have already been processed.
|
|
35
|
+
const onceForChunkSet = new WeakSet();
|
|
36
|
+
// Define a handler function to be called for each chunk in the compilation.
|
|
37
|
+
const handler = (chunk, set) => {
|
|
38
|
+
// If the chunk has already been processed, skip it.
|
|
39
|
+
if (onceForChunkSet.has(chunk))
|
|
40
|
+
return;
|
|
41
|
+
// Mark the chunk as processed by adding it to the WeakSet.
|
|
42
|
+
onceForChunkSet.add(chunk);
|
|
43
|
+
if (chunk.hasRuntime()) {
|
|
44
|
+
// Add an InvertedContainerRuntimeModule to the chunk, which handles
|
|
45
|
+
// the runtime logic for loading remote modules.
|
|
46
|
+
compilation.addRuntimeModule(chunk, new InvertedContainerRuntimeModule_1.default(set, this.options, {
|
|
47
|
+
webpack: compiler.webpack,
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
// Hook the handler function into the compilation process.
|
|
52
|
+
compilation.hooks.additionalChunkRuntimeRequirements.tap('InvertedContainerPlugin', handler);
|
|
53
|
+
compilation.hooks.optimizeChunks.tap('AddModulesToRuntimeChunkPlugin', (chunks) => {
|
|
54
|
+
const containerEntryModule = this.resolveContainerModule(compilation);
|
|
55
|
+
if (!containerEntryModule)
|
|
56
|
+
return;
|
|
57
|
+
for (const chunk of chunks) {
|
|
58
|
+
if (chunk.hasRuntime()) {
|
|
59
|
+
if (!compilation.chunkGraph.isModuleInChunk(containerEntryModule, chunk)) {
|
|
60
|
+
this.options.debug &&
|
|
61
|
+
console.log('adding',
|
|
62
|
+
//@ts-ignore
|
|
63
|
+
containerEntryModule._name, 'to', chunk.name);
|
|
64
|
+
compilation.chunkGraph.connectChunkAndModule(chunk, containerEntryModule);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.default = InvertedContainerPlugin;
|
|
73
|
+
//# sourceMappingURL=InvertedContainerPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InvertedContainerPlugin.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/container/InvertedContainerPlugin.ts"],"names":[],"mappings":";;;AAGA,8GAA8E;AAa9E;;;GAGG;AACH,MAAM,uBAAuB;IAG3B;;;OAGG;IACH,YAAY,OAKX;QACC,IAAI,CAAC,OAAO,GAAG,OAAO,IAAK,EAA+B,CAAC;IAC7D,CAAC;IAED,sBAAsB,CAAC,WAAwB;QAC7C,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;YAC3B,OAAO,SAAS,CAAC;SAClB;QACD,MAAM,SAAS,GAAG,WAAW,CAAC,WAAW;aACtC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,SAAmB,CAAC;YACtC,EAAE,eAAe,EAAE,EAAE,CAAC;QACxB,MAAM,WAAW,GAAG,SAAS,EAAE,WAAW,CAAC;QAC3C,OAAO,WAAW,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAkB;QACtB,qCAAqC;QACrC,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAChC,yBAAyB,EACzB,CAAC,WAAW,EAAE,EAAE;YACd,qEAAqE;YACrE,MAAM,eA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ACrB,CAAC;yBACH;qBACF;iBACF;YACH,CAAC,CACF,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAED,kBAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Compiler } from 'webpack';
|
|
2
|
+
import { RuntimeModule } from 'webpack';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for InvertedContainerRuntimeModuleOptions, containing
|
|
5
|
+
* options for the InvertedContainerRuntimeModule class.
|
|
6
|
+
*/
|
|
7
|
+
interface InvertedContainerRuntimeModuleOptions {
|
|
8
|
+
runtime: string;
|
|
9
|
+
remotes: Record<string, string>;
|
|
10
|
+
name?: string;
|
|
11
|
+
verbose?: boolean;
|
|
12
|
+
container?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Interface for ChunkLoadingContext, containing Webpack-related properties.
|
|
16
|
+
*/
|
|
17
|
+
interface ChunkLoadingContext {
|
|
18
|
+
webpack: Compiler['webpack'];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* InvertedContainerRuntimeModule is a Webpack runtime module that generates
|
|
22
|
+
* the runtime code needed for loading federated modules in an inverted container.
|
|
23
|
+
*/
|
|
24
|
+
declare class InvertedContainerRuntimeModule extends RuntimeModule {
|
|
25
|
+
private runtimeRequirements;
|
|
26
|
+
private options;
|
|
27
|
+
private chunkLoadingContext;
|
|
28
|
+
/**
|
|
29
|
+
* Constructor for the InvertedContainerRuntimeModule.
|
|
30
|
+
* @param {Set<string>} runtimeRequirements - A set of runtime requirement strings.
|
|
31
|
+
* @param {InvertedContainerRuntimeModuleOptions} options - Runtime module options.
|
|
32
|
+
* @param {ChunkLoadingContext} chunkLoadingContext - Chunk loading context.
|
|
33
|
+
*/
|
|
34
|
+
constructor(runtimeRequirements: Set<string>, options: InvertedContainerRuntimeModuleOptions, chunkLoadingContext: ChunkLoadingContext);
|
|
35
|
+
resolveContainerModule(): import("webpack").Module | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Generate method for the runtime module, producing the runtime code.
|
|
38
|
+
* @returns {string} runtime code
|
|
39
|
+
*/
|
|
40
|
+
generate(): string;
|
|
41
|
+
}
|
|
42
|
+
export default InvertedContainerRuntimeModule;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
+
/*
|
|
3
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
4
|
+
*/
|
|
5
|
+
'use strict';
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const webpack_1 = require("webpack");
|
|
8
|
+
/**
|
|
9
|
+
* InvertedContainerRuntimeModule is a Webpack runtime module that generates
|
|
10
|
+
* the runtime code needed for loading federated modules in an inverted container.
|
|
11
|
+
*/
|
|
12
|
+
class InvertedContainerRuntimeModule extends webpack_1.RuntimeModule {
|
|
13
|
+
/**
|
|
14
|
+
* Constructor for the InvertedContainerRuntimeModule.
|
|
15
|
+
* @param {Set<string>} runtimeRequirements - A set of runtime requirement strings.
|
|
16
|
+
* @param {InvertedContainerRuntimeModuleOptions} options - Runtime module options.
|
|
17
|
+
* @param {ChunkLoadingContext} chunkLoadingContext - Chunk loading context.
|
|
18
|
+
*/
|
|
19
|
+
constructor(runtimeRequirements, options, chunkLoadingContext) {
|
|
20
|
+
super('inverted container startup', webpack_1.RuntimeModule.STAGE_ATTACH);
|
|
21
|
+
this.runtimeRequirements = runtimeRequirements;
|
|
22
|
+
this.options = options;
|
|
23
|
+
this.chunkLoadingContext = chunkLoadingContext;
|
|
24
|
+
}
|
|
25
|
+
resolveContainerModule() {
|
|
26
|
+
const container = this.compilation.entrypoints
|
|
27
|
+
.get(this.options.container)
|
|
28
|
+
?.getRuntimeChunk?.();
|
|
29
|
+
const entryModule = container?.entryModule;
|
|
30
|
+
return entryModule;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Generate method for the runtime module, producing the runtime code.
|
|
34
|
+
* @returns {string} runtime code
|
|
35
|
+
*/
|
|
36
|
+
generate() {
|
|
37
|
+
const { name } = this.options;
|
|
38
|
+
const { webpack } = this.chunkLoadingContext;
|
|
39
|
+
const chunkHasJs = (webpack && webpack.javascript.JavascriptModulesPlugin.chunkHasJs) ||
|
|
40
|
+
require('webpack/lib/javascript/JavascriptModulesPlugin').chunkHasJs;
|
|
41
|
+
const containerEntryModule = this.resolveContainerModule();
|
|
42
|
+
const { chunkGraph, chunk } = this;
|
|
43
|
+
const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
|
|
44
|
+
// const hasJsMatcher = compileBooleanMatcher(conditionMap);
|
|
45
|
+
// find the main webpack runtime, skip all other chunks
|
|
46
|
+
if (chunk.name != this.options.runtime && containerEntryModule) {
|
|
47
|
+
return webpack_1.Template.asString('');
|
|
48
|
+
}
|
|
49
|
+
const containerEntry = [containerEntryModule].map((module) => {
|
|
50
|
+
//@ts-ignore
|
|
51
|
+
const containerName = module?._name || name;
|
|
52
|
+
const containerModuleId = module?.id || module?.debugId;
|
|
53
|
+
if (!(containerName && containerName)) {
|
|
54
|
+
return '';
|
|
55
|
+
}
|
|
56
|
+
// const globalRef = this.compilation.options.output?.globalObject;
|
|
57
|
+
//@ts-ignore
|
|
58
|
+
const nodeGlobal = this.compilation.options?.node?.global;
|
|
59
|
+
const globalObject = nodeGlobal
|
|
60
|
+
? webpack.RuntimeGlobals.global
|
|
61
|
+
: 'global';
|
|
62
|
+
return `
|
|
63
|
+
if(typeof window === 'undefined') {
|
|
64
|
+
${globalObject}['__remote_scope__'] = ${globalObject}['__remote_scope__'] || {_config: {}};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
${webpack.RuntimeGlobals.shareScopeMap}['default'] = ${webpack.RuntimeGlobals.shareScopeMap}['default'] || {};
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
var containerAttachObject = typeof window !== 'undefined' ? window : ${globalObject}['__remote_scope__']
|
|
71
|
+
containerAttachObject[${JSON.stringify(
|
|
72
|
+
//@ts-ignore
|
|
73
|
+
containerName)}] = __webpack_require__(${JSON.stringify(containerModuleId)})
|
|
74
|
+
} catch (e) {
|
|
75
|
+
console.error('host runtime was unable to initialize its own remote', e);
|
|
76
|
+
}`;
|
|
77
|
+
});
|
|
78
|
+
return webpack_1.Template.asString(containerEntry);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.default = InvertedContainerRuntimeModule;
|
|
82
|
+
//# sourceMappingURL=InvertedContainerRuntimeModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InvertedContainerRuntimeModule.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/container/InvertedContainerRuntimeModule.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD;;EAEE;AAEF,YAAY,CAAC;;AAGb,qCAAkD;AAyBlD;;;GAGG;AACH,MAAM,8BAA+B,SAAQ,uBAAa;IAKxD;;;;;OAKG;IACH,YACE,mBAAgC,EAChC,OAA8C,EAC9C,mBAAwC;QAExC,KAAK,CAAC,4BAA4B,EAAE,uBAAa,CAAC,YAAY,CAAC,CAAC;QAChE,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QAE/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;IACjD,CAAC;IAED,sBAAsB;QACpB,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW;aAC3C,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,SAAmB,CAAC;YACtC,EAAE,eAAe,EAAE,EAAE,CAAC;QACxB,MAAM,WAAW,GAAG,SAAS,EAAE,WAAW,CAAC;QAC3C,OAAO,WAAW,CAAC;IACrB,CAAC;IACD;;;OAGG;IACM,QAAQ;QACf,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAE9B,MAAM,EAAE,OAAO,EAAE,G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AY;gCAC3D,IAAI,CAAC,SAAS;YACpC,YAAY;YACZ,aAAa,CACd,2BAA2B,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC;;;QAG7D,CAAC;QACL,CAAC,CAAC,CAAC;QACH,OAAO,kBAAQ,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;IAC3C,CAAC;CACF;AAED,kBAAe,8BAA8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/container/types.ts"],"names":[],"mappings":""}
|
package/utils/Template.d.ts
CHANGED