@module-federation/nextjs-mf 0.0.0-feat-node-support-1702694175665
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/client/UrlNode.d.ts +17 -0
- package/client/UrlNode.js +150 -0
- package/client/UrlNode.js.map +1 -0
- package/node.d.ts +1 -0
- package/node.js +18 -0
- package/node.js.map +1 -0
- package/package.json +44 -0
- package/src/default-delegate.cjs +308 -0
- package/src/default-delegate.d.ts +1 -0
- package/src/default-delegate.js.map +1 -0
- package/src/federation-noop.cjs +15 -0
- package/src/federation-noop.d.ts +0 -0
- package/src/federation-noop.js.map +1 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +12 -0
- package/src/index.js.map +1 -0
- package/src/internal.d.ts +48 -0
- package/src/internal.js +256 -0
- package/src/internal.js.map +1 -0
- package/src/loaders/delegateLoader.d.ts +10 -0
- package/src/loaders/delegateLoader.js +46 -0
- package/src/loaders/delegateLoader.js.map +1 -0
- package/src/loaders/fixImageLoader.d.ts +22 -0
- package/src/loaders/fixImageLoader.js +118 -0
- package/src/loaders/fixImageLoader.js.map +1 -0
- package/src/loaders/fixUrlLoader.d.ts +13 -0
- package/src/loaders/fixUrlLoader.js +25 -0
- package/src/loaders/fixUrlLoader.js.map +1 -0
- package/src/loaders/helpers.d.ts +17 -0
- package/src/loaders/helpers.js +60 -0
- package/src/loaders/helpers.js.map +1 -0
- package/src/loaders/nextPageMapLoader.d.ts +24 -0
- package/src/loaders/nextPageMapLoader.js +167 -0
- package/src/loaders/nextPageMapLoader.js.map +1 -0
- package/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.d.ts +5 -0
- package/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js +19 -0
- package/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js.map +1 -0
- package/src/plugins/CopyFederationPlugin.d.ts +20 -0
- package/src/plugins/CopyFederationPlugin.js +71 -0
- package/src/plugins/CopyFederationPlugin.js.map +1 -0
- package/src/plugins/NextFederationPlugin/apply-client-plugins.d.ts +23 -0
- package/src/plugins/NextFederationPlugin/apply-client-plugins.js +72 -0
- package/src/plugins/NextFederationPlugin/apply-client-plugins.js.map +1 -0
- package/src/plugins/NextFederationPlugin/apply-server-plugins.d.ts +60 -0
- package/src/plugins/NextFederationPlugin/apply-server-plugins.js +173 -0
- package/src/plugins/NextFederationPlugin/apply-server-plugins.js.map +1 -0
- package/src/plugins/NextFederationPlugin/index.d.ts +30 -0
- package/src/plugins/NextFederationPlugin/index.js +148 -0
- package/src/plugins/NextFederationPlugin/index.js.map +1 -0
- package/src/plugins/NextFederationPlugin/next-fragments.d.ts +18 -0
- package/src/plugins/NextFederationPlugin/next-fragments.js +65 -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 +8 -0
- package/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js +31 -0
- package/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js.map +1 -0
- package/src/plugins/NextFederationPlugin/set-options.d.ts +20 -0
- package/src/plugins/NextFederationPlugin/set-options.js +38 -0
- package/src/plugins/NextFederationPlugin/set-options.js.map +1 -0
- package/src/plugins/NextFederationPlugin/validate-options.d.ts +25 -0
- package/src/plugins/NextFederationPlugin/validate-options.js +46 -0
- package/src/plugins/NextFederationPlugin/validate-options.js.map +1 -0
- package/src/plugins/container/EmbeddedContainerPlugin.d.ts +40 -0
- package/src/plugins/container/EmbeddedContainerPlugin.js +73 -0
- package/src/plugins/container/EmbeddedContainerPlugin.js.map +1 -0
- package/src/plugins/container/HoistPseudoEagerModules.d.ts +19 -0
- package/src/plugins/container/HoistPseudoEagerModules.js +79 -0
- package/src/plugins/container/HoistPseudoEagerModules.js.map +1 -0
- package/src/plugins/container/InvertedContainerPlugin.d.ts +15 -0
- package/src/plugins/container/InvertedContainerPlugin.js +25 -0
- package/src/plugins/container/InvertedContainerPlugin.js.map +1 -0
- package/src/plugins/container/InvertedContainerRuntimeModule.d.ts +15 -0
- package/src/plugins/container/InvertedContainerRuntimeModule.js +65 -0
- package/src/plugins/container/InvertedContainerRuntimeModule.js.map +1 -0
- package/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.d.ts +39 -0
- package/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js +72 -0
- package/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js.map +1 -0
- package/src/plugins/container/runtimePlugin.d.ts +2 -0
- package/src/plugins/container/runtimePlugin.js +64 -0
- package/src/plugins/container/runtimePlugin.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/src/types.d.ts +28 -0
- package/src/types.js +3 -0
- package/src/types.js.map +1 -0
- package/utilities.d.ts +1 -0
- package/utilities.js +18 -0
- package/utilities.js.map +1 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { LoaderContext } from 'webpack';
|
|
2
|
+
/**
|
|
3
|
+
* Webpack loader which prepares MF map for NextJS pages.
|
|
4
|
+
* This function is the main entry point for the loader.
|
|
5
|
+
* It gets the options passed to the loader and prepares the pages map.
|
|
6
|
+
* If the 'v2' option is passed, it prepares the pages map using the 'preparePageMapV2' function.
|
|
7
|
+
* Otherwise, it uses the 'preparePageMap' function.
|
|
8
|
+
* Finally, it calls the loader's callback function with the prepared pages map.
|
|
9
|
+
*
|
|
10
|
+
* @param {LoaderContext<Record<string, unknown>>} this - The loader context.
|
|
11
|
+
*/
|
|
12
|
+
export default function nextPageMapLoader(this: LoaderContext<Record<string, unknown>>): void;
|
|
13
|
+
/**
|
|
14
|
+
* Webpack config generator for `exposes` option.
|
|
15
|
+
* This function generates the webpack config for the 'exposes' option.
|
|
16
|
+
* It creates a map of pages to modules and returns an object with the pages map and the pages map v2.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} cwd - The current working directory.
|
|
19
|
+
* @returns {Record<string, string>} The webpack config for the 'exposes' option.
|
|
20
|
+
*/
|
|
21
|
+
export declare function exposeNextjsPages(cwd: string): {
|
|
22
|
+
'./pages-map': string;
|
|
23
|
+
'./pages-map-v2': string;
|
|
24
|
+
};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.exposeNextjsPages = void 0;
|
|
7
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const UrlNode_1 = require("../../client/UrlNode");
|
|
10
|
+
/**
|
|
11
|
+
* Webpack loader which prepares MF map for NextJS pages.
|
|
12
|
+
* This function is the main entry point for the loader.
|
|
13
|
+
* It gets the options passed to the loader and prepares the pages map.
|
|
14
|
+
* If the 'v2' option is passed, it prepares the pages map using the 'preparePageMapV2' function.
|
|
15
|
+
* Otherwise, it uses the 'preparePageMap' function.
|
|
16
|
+
* Finally, it calls the loader's callback function with the prepared pages map.
|
|
17
|
+
*
|
|
18
|
+
* @param {LoaderContext<Record<string, unknown>>} this - The loader context.
|
|
19
|
+
*/
|
|
20
|
+
function nextPageMapLoader() {
|
|
21
|
+
// const [pagesRoot] = getNextPagesRoot(this.rootContext);
|
|
22
|
+
// this.addContextDependency(pagesRoot);
|
|
23
|
+
const opts = this.getOptions();
|
|
24
|
+
const pages = getNextPages(this.rootContext);
|
|
25
|
+
let result = {};
|
|
26
|
+
if (Object.hasOwnProperty.call(opts, 'v2')) {
|
|
27
|
+
result = preparePageMapV2(pages);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
result = preparePageMap(pages);
|
|
31
|
+
}
|
|
32
|
+
this.callback(null, `module.exports = { default: ${JSON.stringify(result)} };`);
|
|
33
|
+
}
|
|
34
|
+
exports.default = nextPageMapLoader;
|
|
35
|
+
/**
|
|
36
|
+
* Webpack config generator for `exposes` option.
|
|
37
|
+
* This function generates the webpack config for the 'exposes' option.
|
|
38
|
+
* It creates a map of pages to modules and returns an object with the pages map and the pages map v2.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} cwd - The current working directory.
|
|
41
|
+
* @returns {Record<string, string>} The webpack config for the 'exposes' option.
|
|
42
|
+
*/
|
|
43
|
+
function exposeNextjsPages(cwd) {
|
|
44
|
+
const pages = getNextPages(cwd);
|
|
45
|
+
const pageModulesMap = {};
|
|
46
|
+
pages.forEach((page) => {
|
|
47
|
+
// Creating a map of pages to modules
|
|
48
|
+
// './pages/storage/index': './pages/storage/index.tsx',
|
|
49
|
+
// './pages/storage/[...slug]': './pages/storage/[...slug].tsx',
|
|
50
|
+
pageModulesMap['./' + sanitizePagePath(page)] = `./${page}`;
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
'./pages-map': `${__filename}!${__filename}`,
|
|
54
|
+
'./pages-map-v2': `${__filename}?v2!${__filename}`,
|
|
55
|
+
...pageModulesMap,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
exports.exposeNextjsPages = exposeNextjsPages;
|
|
59
|
+
/**
|
|
60
|
+
* This function gets the root directory of the NextJS pages.
|
|
61
|
+
* It checks if the 'src/pages/' directory exists.
|
|
62
|
+
* If it does, it returns the absolute path and the relative path to this directory.
|
|
63
|
+
* If it doesn't, it returns the absolute path and the relative path to the 'pages/' directory.
|
|
64
|
+
*
|
|
65
|
+
* @param {string} appRoot - The root directory of the application.
|
|
66
|
+
* @returns {[string, string]} The absolute path and the relative path to the pages directory.
|
|
67
|
+
*/
|
|
68
|
+
function getNextPagesRoot(appRoot) {
|
|
69
|
+
let pagesDir = 'src/pages/';
|
|
70
|
+
let absPageDir = `${appRoot}/${pagesDir}`;
|
|
71
|
+
if (!fs_1.default.existsSync(absPageDir)) {
|
|
72
|
+
pagesDir = 'pages/';
|
|
73
|
+
absPageDir = `${appRoot}/${pagesDir}`;
|
|
74
|
+
}
|
|
75
|
+
return [absPageDir, pagesDir];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* This function scans the pages directory and returns a list of user defined pages.
|
|
79
|
+
* It excludes special pages like '_app', '_document', '_error', '404', '500', and federation pages.
|
|
80
|
+
*
|
|
81
|
+
* @param {string} rootDir - The root directory of the application.
|
|
82
|
+
* @returns {string[]} The list of user defined pages.
|
|
83
|
+
*/
|
|
84
|
+
function getNextPages(rootDir) {
|
|
85
|
+
const [cwd, pagesDir] = getNextPagesRoot(rootDir);
|
|
86
|
+
// scan all files in pages folder except pages/api
|
|
87
|
+
let pageList = fast_glob_1.default.sync('**/*.{ts,tsx,js,jsx}', {
|
|
88
|
+
cwd,
|
|
89
|
+
onlyFiles: true,
|
|
90
|
+
ignore: ['api/**'],
|
|
91
|
+
});
|
|
92
|
+
// remove specific nextjs pages
|
|
93
|
+
const exclude = [
|
|
94
|
+
/^_app\..*/,
|
|
95
|
+
/^_document\..*/,
|
|
96
|
+
/^_error\..*/,
|
|
97
|
+
/^404\..*/,
|
|
98
|
+
/^500\..*/,
|
|
99
|
+
/^\[\.\.\..*\]\..*/, // /[...federationPage].tsx
|
|
100
|
+
];
|
|
101
|
+
pageList = pageList.filter((page) => {
|
|
102
|
+
return !exclude.some((r) => r.test(page));
|
|
103
|
+
});
|
|
104
|
+
pageList = pageList.map((page) => `${pagesDir}${page}`);
|
|
105
|
+
return pageList;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* This function sanitizes a page path.
|
|
109
|
+
* It removes the 'src/pages/' prefix and the file extension.
|
|
110
|
+
*
|
|
111
|
+
* @param {string} item - The page path to sanitize.
|
|
112
|
+
* @returns {string} The sanitized page path.
|
|
113
|
+
*/
|
|
114
|
+
function sanitizePagePath(item) {
|
|
115
|
+
return item
|
|
116
|
+
.replace(/^src\/pages\//i, 'pages/')
|
|
117
|
+
.replace(/\.(ts|tsx|js|jsx)$/, '');
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* This function creates a MF map from a list of NextJS pages.
|
|
121
|
+
* It sanitizes the page paths and sorts them using the 'UrlNode' class.
|
|
122
|
+
* Then, it creates a map with the sorted page paths as keys and the original page paths as values.
|
|
123
|
+
*
|
|
124
|
+
* @param {string[]} pages - The list of NextJS pages.
|
|
125
|
+
* @returns {Record<string, string>} The MF map.
|
|
126
|
+
*/
|
|
127
|
+
function preparePageMap(pages) {
|
|
128
|
+
const result = {};
|
|
129
|
+
const clearedPages = pages.map((p) => `/${sanitizePagePath(p)}`);
|
|
130
|
+
// getSortedRoutes @see https://github.com/vercel/next.js/blob/canary/packages/next/shared/lib/router/utils/sorted-routes.ts
|
|
131
|
+
const root = new UrlNode_1.UrlNode();
|
|
132
|
+
clearedPages.forEach((pagePath) => root.insert(pagePath));
|
|
133
|
+
// Smoosh will then sort those sublevels up to the point where you get the correct route definition priority
|
|
134
|
+
const sortedPages = root.smoosh();
|
|
135
|
+
sortedPages.forEach((page) => {
|
|
136
|
+
let key = page
|
|
137
|
+
.replace(/\[\.\.\.[^\]]+\]/gi, '*')
|
|
138
|
+
.replace(/\[([^\]]+)\]/gi, ':$1');
|
|
139
|
+
key = key.replace(/^\/pages\//, '/').replace(/\/index$/, '') || '/';
|
|
140
|
+
result[key] = `.${page}`;
|
|
141
|
+
});
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* This function creates a MF list from a list of NextJS pages.
|
|
146
|
+
* It sanitizes the page paths and sorts them using the 'UrlNode' class.
|
|
147
|
+
* Then, it creates a map with the sorted page paths as keys and the original page paths as values.
|
|
148
|
+
* Unlike the 'preparePageMap' function, this function does not replace the '[...]' and '[]' parts in the page paths.
|
|
149
|
+
*
|
|
150
|
+
* @param {string[]} pages - The list of NextJS pages.
|
|
151
|
+
* @returns {Record<string, string>} The MF list.
|
|
152
|
+
*/
|
|
153
|
+
function preparePageMapV2(pages) {
|
|
154
|
+
const result = {};
|
|
155
|
+
const clearedPages = pages.map((p) => `/${sanitizePagePath(p)}`);
|
|
156
|
+
// getSortedRoutes @see https://github.com/vercel/next.js/blob/canary/packages/next/shared/lib/router/utils/sorted-routes.ts
|
|
157
|
+
const root = new UrlNode_1.UrlNode();
|
|
158
|
+
clearedPages.forEach((pagePath) => root.insert(pagePath));
|
|
159
|
+
// Smoosh will then sort those sublevels up to the point where you get the correct route definition priority
|
|
160
|
+
const sortedPages = root.smoosh();
|
|
161
|
+
sortedPages.forEach((page) => {
|
|
162
|
+
const key = page.replace(/^\/pages\//, '/').replace(/\/index$/, '') || '/';
|
|
163
|
+
result[key] = `.${page}`;
|
|
164
|
+
});
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=nextPageMapLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nextPageMapLoader.js","sourceRoot":"","sources":["../../../../../packages/nextjs-mf/src/loaders/nextPageMapLoader.ts"],"names":[],"mappings":";;;;;;AAEA,0DAA2B;AAC3B,4CAAoB;AAEpB,kDAA+C;AAE/C;;;;;;;;;GASG;AACH,SAAwB,iBAAiB;IAGvC,0DAA0D;IAC1D,wCAAwC;IACxC,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IAC/B,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAE7C,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,IAAI,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;QAC1C,MAAM,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;KAClC;SAAM;QACL,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;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,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AddRuntimeRequirementToPromiseExternal = void 0;
|
|
4
|
+
class AddRuntimeRequirementToPromiseExternal {
|
|
5
|
+
apply(compiler) {
|
|
6
|
+
compiler.hooks.compilation.tap('AddRuntimeRequirementToPromiseExternal', (compilation) => {
|
|
7
|
+
const { RuntimeGlobals } = compiler.webpack;
|
|
8
|
+
compilation.hooks.additionalModuleRuntimeRequirements.tap('AddRuntimeRequirementToPromiseExternal', (module, set) => {
|
|
9
|
+
if (module.externalType === 'promise') {
|
|
10
|
+
set.add(RuntimeGlobals.loadScript);
|
|
11
|
+
set.add(RuntimeGlobals.require);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.AddRuntimeRequirementToPromiseExternal = AddRuntimeRequirementToPromiseExternal;
|
|
18
|
+
exports.default = AddRuntimeRequirementToPromiseExternal;
|
|
19
|
+
//# sourceMappingURL=AddRuntimeRequirementToPromiseExternalPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AddRuntimeRequirementToPromiseExternalPlugin.js","sourceRoot":"","sources":["../../../../../packages/nextjs-mf/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.ts"],"names":[],"mappings":";;;AAEA,MAAa,sCAAsC;IAGjD,KAAK,CAAC,QAAkB;QACtB,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAC5B,wCAAwC,EACxC,CAAC,WAAW,EAAE,EAAE;YACd,MAAM,EAAE,cAAc,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAC;YAC5C,WAAW,CAAC,KAAK,CAAC,mCAAmC,CAAC,GAAG,CACvD,wCAAwC,EACxC,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;gBACd,IAAK,MAAc,CAAC,YAAY,KAAK,SAAS,EAAE;oBAC9C,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;oBACnC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;iBACjC;YACH,CAAC,CACF,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AApBD,wFAoBC;AAED,kBAAe,sCAAsC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Compiler, WebpackPluginInstance } from 'webpack';
|
|
2
|
+
/**
|
|
3
|
+
* Plugin to copy build output files.
|
|
4
|
+
* @class
|
|
5
|
+
*/
|
|
6
|
+
declare class CopyBuildOutputPlugin implements WebpackPluginInstance {
|
|
7
|
+
private isServer;
|
|
8
|
+
/**
|
|
9
|
+
* @param {boolean} isServer - Indicates if the current environment is server.
|
|
10
|
+
* @constructor
|
|
11
|
+
*/
|
|
12
|
+
constructor(isServer: boolean);
|
|
13
|
+
/**
|
|
14
|
+
* Applies the plugin to the compiler.
|
|
15
|
+
* @param {Compiler} compiler - The webpack compiler object.
|
|
16
|
+
* @method
|
|
17
|
+
*/
|
|
18
|
+
apply(compiler: Compiler): void;
|
|
19
|
+
}
|
|
20
|
+
export default CopyBuildOutputPlugin;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
/**
|
|
9
|
+
* Plugin to copy build output files.
|
|
10
|
+
* @class
|
|
11
|
+
*/
|
|
12
|
+
class CopyBuildOutputPlugin {
|
|
13
|
+
/**
|
|
14
|
+
* @param {boolean} isServer - Indicates if the current environment is server.
|
|
15
|
+
* @constructor
|
|
16
|
+
*/
|
|
17
|
+
constructor(isServer) {
|
|
18
|
+
this.isServer = isServer;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Applies the plugin to the compiler.
|
|
22
|
+
* @param {Compiler} compiler - The webpack compiler object.
|
|
23
|
+
* @method
|
|
24
|
+
*/
|
|
25
|
+
apply(compiler) {
|
|
26
|
+
/**
|
|
27
|
+
* Copies files from source to destination.
|
|
28
|
+
* @param {string} source - The source directory.
|
|
29
|
+
* @param {string} destination - The destination directory.
|
|
30
|
+
* @async
|
|
31
|
+
* @function
|
|
32
|
+
*/
|
|
33
|
+
const copyFiles = async (source, destination) => {
|
|
34
|
+
const files = await fs_1.promises.readdir(source);
|
|
35
|
+
await Promise.all(files.map(async (file) => {
|
|
36
|
+
const sourcePath = path_1.default.join(source, file);
|
|
37
|
+
const destinationPath = path_1.default.join(destination, file);
|
|
38
|
+
if ((await fs_1.promises.lstat(sourcePath)).isDirectory()) {
|
|
39
|
+
await fs_1.promises.mkdir(destinationPath, { recursive: true });
|
|
40
|
+
await copyFiles(sourcePath, destinationPath);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
await fs_1.promises.copyFile(sourcePath, destinationPath);
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
};
|
|
47
|
+
compiler.hooks.afterEmit.tapPromise('CopyBuildOutputPlugin', async (compilation) => {
|
|
48
|
+
const { outputPath } = compiler;
|
|
49
|
+
const outputString = outputPath.split('server')[0];
|
|
50
|
+
const isProd = compiler.options.mode === 'production';
|
|
51
|
+
if (!isProd && !this.isServer) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const serverLoc = path_1.default.join(outputString, this.isServer && isProd ? '/ssr' : '/static/ssr');
|
|
55
|
+
const servingLoc = path_1.default.join(outputPath, 'ssr');
|
|
56
|
+
await fs_1.promises.mkdir(serverLoc, { recursive: true });
|
|
57
|
+
const sourcePath = this.isServer ? outputPath : servingLoc;
|
|
58
|
+
try {
|
|
59
|
+
await fs_1.promises.access(sourcePath);
|
|
60
|
+
// If the promise resolves, the file exists and you can proceed with copying.
|
|
61
|
+
await copyFiles(sourcePath, serverLoc);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
// If the promise rejects, the file does not exist.
|
|
65
|
+
console.error(`File at ${sourcePath} does not exist.`);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.default = CopyBuildOutputPlugin;
|
|
71
|
+
//# sourceMappingURL=CopyFederationPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CopyFederationPlugin.js","sourceRoot":"","sources":["../../../../../packages/nextjs-mf/src/plugins/CopyFederationPlugin.ts"],"names":[],"mappings":";;;;;AAAA,2BAAoC;AACpC,gDAAwB;AAGxB;;;GAGG;AACH,MAAM,qBAAqB;IAGzB;;;OAGG;IACH,YAAY,QAAiB;QAC3B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,QAAkB;QACtB;;;;;;WAMG;QACH,MAAM,SAAS,GAAG,KAAK,EACrB,MAAc,EACd,WAAmB,EACJ,EAAE;YACjB,MAAM,KAAK,GAAG,MAAM,aAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAEvC,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;gBACvB,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAC3C,MAAM,eAAe,GAAG,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;gBAErD,IAAI,CAAC,MAAM,aAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE;oBAC9C,MAAM,aAAE,CAAC,KAAK,CAAC,eAAe,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,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W,UAAU,kBAAkB,CAAC,CAAC;aACxD;QACH,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAED,kBAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Compiler } from 'webpack';
|
|
2
|
+
import { ModuleFederationPluginOptions, NextFederationPluginExtraOptions } from '@module-federation/utilities';
|
|
3
|
+
/**
|
|
4
|
+
* Applies client-specific plugins.
|
|
5
|
+
*
|
|
6
|
+
* @param compiler - The Webpack compiler instance.
|
|
7
|
+
* @param options - The ModuleFederationPluginOptions instance.
|
|
8
|
+
* @param extraOptions - The NextFederationPluginExtraOptions instance.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* This function applies plugins to the Webpack compiler instance that are specific to the client build of
|
|
12
|
+
* a Next.js application with Module Federation enabled. These plugins include the following:
|
|
13
|
+
*
|
|
14
|
+
* - DelegateModulesPlugin: Delegates modules to the webpack container runtime that can be streamed to other runtimes.
|
|
15
|
+
* - ChunkCorrelationPlugin: Collects metadata on chunks to enable proper module loading across different runtimes.
|
|
16
|
+
* - InvertedContainerPlugin: Adds custom runtime modules to the container runtime to allow a host to expose its
|
|
17
|
+
* own remote interface at startup.
|
|
18
|
+
*
|
|
19
|
+
* If automatic page stitching is enabled, a loader is added to process the `next/dist/client/page-loader.js`
|
|
20
|
+
* file. If a custom library is specified in the options, an error is thrown. The options.library property is
|
|
21
|
+
* also set to `{ type: 'window', name: options.name }`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function applyClientPlugins(compiler: Compiler, options: ModuleFederationPluginOptions, extraOptions: NextFederationPluginExtraOptions): void;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.applyClientPlugins = void 0;
|
|
7
|
+
const node_1 = require("@module-federation/node");
|
|
8
|
+
const InvertedContainerPlugin_1 = __importDefault(require("../container/InvertedContainerPlugin"));
|
|
9
|
+
const HoistContainerReferencesPlugin_1 = require("@module-federation/enhanced/src/lib/container/HoistContainerReferencesPlugin");
|
|
10
|
+
/**
|
|
11
|
+
* Applies client-specific plugins.
|
|
12
|
+
*
|
|
13
|
+
* @param compiler - The Webpack compiler instance.
|
|
14
|
+
* @param options - The ModuleFederationPluginOptions instance.
|
|
15
|
+
* @param extraOptions - The NextFederationPluginExtraOptions instance.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* This function applies plugins to the Webpack compiler instance that are specific to the client build of
|
|
19
|
+
* a Next.js application with Module Federation enabled. These plugins include the following:
|
|
20
|
+
*
|
|
21
|
+
* - DelegateModulesPlugin: Delegates modules to the webpack container runtime that can be streamed to other runtimes.
|
|
22
|
+
* - ChunkCorrelationPlugin: Collects metadata on chunks to enable proper module loading across different runtimes.
|
|
23
|
+
* - InvertedContainerPlugin: Adds custom runtime modules to the container runtime to allow a host to expose its
|
|
24
|
+
* own remote interface at startup.
|
|
25
|
+
*
|
|
26
|
+
* If automatic page stitching is enabled, a loader is added to process the `next/dist/client/page-loader.js`
|
|
27
|
+
* file. If a custom library is specified in the options, an error is thrown. The options.library property is
|
|
28
|
+
* also set to `{ type: 'window', name: options.name }`.
|
|
29
|
+
*/
|
|
30
|
+
function applyClientPlugins(compiler, options, extraOptions) {
|
|
31
|
+
const { webpack } = compiler;
|
|
32
|
+
const { remotes, name } = options;
|
|
33
|
+
//@ts-ignore
|
|
34
|
+
compiler.options.output.publicPath = 'auto';
|
|
35
|
+
// Build will hang without this. Likely something in my plugin
|
|
36
|
+
new HoistContainerReferencesPlugin_1.HoistContainerReferences().apply(compiler);
|
|
37
|
+
// If automatic page stitching is enabled, add a new rule to the compiler's module rules
|
|
38
|
+
if (extraOptions.automaticPageStitching) {
|
|
39
|
+
console.warn('[nextjs-mf]', 'automatic page stitching is disabled in v7');
|
|
40
|
+
}
|
|
41
|
+
// If a custom library is set, log an error message
|
|
42
|
+
if (options.library) {
|
|
43
|
+
console.error('[nextjs-mf] you cannot set custom library');
|
|
44
|
+
}
|
|
45
|
+
// Set the library option to be a window object with the name of the module federation plugin
|
|
46
|
+
options.library = {
|
|
47
|
+
type: 'window',
|
|
48
|
+
name,
|
|
49
|
+
};
|
|
50
|
+
// Add a new chunk correlation plugin to the compiler
|
|
51
|
+
new node_1.ChunkCorrelationPlugin({
|
|
52
|
+
filename: [
|
|
53
|
+
'static/chunks/federated-stats.json',
|
|
54
|
+
'server/federated-stats.json',
|
|
55
|
+
],
|
|
56
|
+
//@ts-ignore
|
|
57
|
+
}).apply(compiler);
|
|
58
|
+
// Add a new commonjs chunk loading plugin to the compiler
|
|
59
|
+
new InvertedContainerPlugin_1.default({
|
|
60
|
+
runtime: 'webpack',
|
|
61
|
+
chunkToEmbed: 'host_inner_ctn',
|
|
62
|
+
container: options.name,
|
|
63
|
+
remotes: options.remotes,
|
|
64
|
+
shared: options.shared,
|
|
65
|
+
shareScope: 'default',
|
|
66
|
+
exposes: options.exposes,
|
|
67
|
+
debug: extraOptions.debug,
|
|
68
|
+
//@ts-ignore
|
|
69
|
+
}).apply(compiler);
|
|
70
|
+
}
|
|
71
|
+
exports.applyClientPlugins = applyClientPlugins;
|
|
72
|
+
//# sourceMappingURL=apply-client-plugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-client-plugins.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/NextFederationPlugin/apply-client-plugins.ts"],"names":[],"mappings":";;;;;;AAKA,kDAAiE;AACjE,mGAA2E;AAC3E,iIAAwH;AAExH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,kBAAkB,CAChC,QAAkB,EAClB,OAAsC,EACtC,YAA8C;IAE9C,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;IAC7B,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IAClC,YAAY;IACZ,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC;IAC5C,8DAA8D;IAE9D,IAAI,yDAAwB,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAE/C,wFAAwF;IACxF,IAAI,YAAY,CAAC,sBAAsB,EAAE;QACvC,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,4CAA4C,CAAC,CAAC;KAC3E;IAED,mDAAmD;IACnD,IAAI,OAAO,CAAC,OAAO,EAAE;QACnB,OAAO,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;KAC5D;IAED,6FAA6F;IAC7F,OAAO,CAAC,OAAO,GAAG;QAChB,IAAI,EAAE,QAAQ;QACd,IAAI;KACL,CAAC;IAEF,qDAAqD;IACrD,IAAI,6BAAsB,CAAC;QACzB,QAAQ,EAAE;YACR,oCAAoC;YACpC,6BAA6B;SAC9B;QACD,YAAY;KACb,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEnB,0DAA0D;IAC1D,IAAI,iCAAuB,CAAC;QAC1B,OAAO,EAAE,SAAS;QAClB,YAAY,EAAE,gBAAgB;QAC9B,SAAS,EAAE,OAAO,CAAC,IAAI;QACvB,OAAO,EAAE,OAAO,CAAC,OAAiC;QAClD,MAAM,EAAE,OAAO,CAAC,MAAa;QAC7B,UAAU,EAAE,SAAS;QACrB,OAAO,EAAE,OAAO,CAAC,OAAc;QAC/B,KAAK,EAAE,YAAY,CAAC,KAAK;QACzB,YAAY;KACb,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AACrB,CAAC;AAlDD,gDAkDC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Compiler } from 'webpack';
|
|
2
|
+
import { ModuleFederationPluginOptions } from '@module-federation/utilities';
|
|
3
|
+
/**
|
|
4
|
+
* This function applies server-specific plugins to the webpack compiler.
|
|
5
|
+
*
|
|
6
|
+
* @param {Compiler} compiler - The Webpack compiler instance.
|
|
7
|
+
* @param {ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
|
|
8
|
+
*
|
|
9
|
+
* @returns {void}
|
|
10
|
+
*/
|
|
11
|
+
export declare function applyServerPlugins(compiler: Compiler, options: ModuleFederationPluginOptions): void;
|
|
12
|
+
/**
|
|
13
|
+
* This function configures server-specific library and filename options.
|
|
14
|
+
*
|
|
15
|
+
* @param {ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
|
|
16
|
+
*
|
|
17
|
+
* @returns {void}
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* This function configures the library and filename options for server builds. The library option is
|
|
21
|
+
* set to the commonjs-module format for chunks and the container, which allows them to be streamed over
|
|
22
|
+
* to hosts with the NodeFederationPlugin. The filename option is set to the basename of the current
|
|
23
|
+
* filename.
|
|
24
|
+
*/
|
|
25
|
+
export declare function configureServerLibraryAndFilename(options: ModuleFederationPluginOptions): void;
|
|
26
|
+
/**
|
|
27
|
+
* This function patches Next.js' default externals function to make sure shared modules are bundled and not treated as external.
|
|
28
|
+
*
|
|
29
|
+
* @param {Compiler} compiler - The Webpack compiler instance.
|
|
30
|
+
* @param {ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
|
|
31
|
+
*
|
|
32
|
+
* @returns {void}
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* In server builds, all node modules are treated as external, which prevents them from being shared
|
|
36
|
+
* via module federation. To work around this limitation, we mark shared modules as internalizable
|
|
37
|
+
* modules that webpack puts into chunks that can be streamed to other runtimes as needed.
|
|
38
|
+
*
|
|
39
|
+
* This function replaces Next.js' default externals function with a new asynchronous function that
|
|
40
|
+
* checks whether a module should be treated as external. If the module should not be treated as
|
|
41
|
+
* external, the function returns without calling the original externals function. Otherwise, the
|
|
42
|
+
* function calls the original externals function and retrieves the result. If the result is null,
|
|
43
|
+
* the function returns without further processing. If the module is from Next.js or React, the
|
|
44
|
+
* function returns the original result. Otherwise, the function returns null.
|
|
45
|
+
*/
|
|
46
|
+
export declare function handleServerExternals(compiler: Compiler, options: ModuleFederationPluginOptions): void;
|
|
47
|
+
/**
|
|
48
|
+
* This function configures server-specific compiler options.
|
|
49
|
+
*
|
|
50
|
+
* @param {Compiler} compiler - The Webpack compiler instance.
|
|
51
|
+
*
|
|
52
|
+
* @returns {void}
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* This function configures the compiler options for server builds. It turns off the compiler target on node
|
|
56
|
+
* builds because it adds its own chunk loading runtime module with NodeFederationPlugin and StreamingTargetPlugin.
|
|
57
|
+
* It also disables split chunks to prevent conflicts from occurring in the graph.
|
|
58
|
+
*
|
|
59
|
+
*/
|
|
60
|
+
export declare function configureServerCompilerOptions(compiler: Compiler): void;
|