@module-federation/nextjs-mf 0.0.0-docs-remove-invalid-lark-link-20251205062649
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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/client/UrlNode.d.ts +17 -0
- package/dist/client/UrlNode.js +150 -0
- package/dist/client/UrlNode.js.map +1 -0
- package/dist/node.d.ts +1 -0
- package/dist/node.js +18 -0
- package/dist/node.js.map +1 -0
- package/dist/package.json +71 -0
- package/dist/src/federation-noop.cjs +15 -0
- package/dist/src/federation-noop.d.ts +0 -0
- package/dist/src/federation-noop.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +12 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/internal.d.ts +50 -0
- package/dist/src/internal.js +255 -0
- package/dist/src/internal.js.map +1 -0
- package/dist/src/loaders/fixImageLoader.d.ts +22 -0
- package/dist/src/loaders/fixImageLoader.js +116 -0
- package/dist/src/loaders/fixImageLoader.js.map +1 -0
- package/dist/src/loaders/fixUrlLoader.d.ts +13 -0
- package/dist/src/loaders/fixUrlLoader.js +24 -0
- package/dist/src/loaders/fixUrlLoader.js.map +1 -0
- package/dist/src/loaders/helpers.d.ts +17 -0
- package/dist/src/loaders/helpers.js +134 -0
- package/dist/src/loaders/helpers.js.map +1 -0
- package/dist/src/loaders/nextPageMapLoader.d.ts +24 -0
- package/dist/src/loaders/nextPageMapLoader.js +166 -0
- package/dist/src/loaders/nextPageMapLoader.js.map +1 -0
- package/dist/src/logger.d.ts +2 -0
- package/dist/src/logger.js +9 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.d.ts +5 -0
- package/dist/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js +19 -0
- package/dist/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js.map +1 -0
- package/dist/src/plugins/CopyFederationPlugin.d.ts +20 -0
- package/dist/src/plugins/CopyFederationPlugin.js +74 -0
- package/dist/src/plugins/CopyFederationPlugin.js.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.d.ts +23 -0
- package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js +58 -0
- package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.d.ts +36 -0
- package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js +135 -0
- package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/index.d.ts +27 -0
- package/dist/src/plugins/NextFederationPlugin/index.js +186 -0
- package/dist/src/plugins/NextFederationPlugin/index.js.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/next-fragments.d.ts +20 -0
- package/dist/src/plugins/NextFederationPlugin/next-fragments.js +100 -0
- package/dist/src/plugins/NextFederationPlugin/next-fragments.js.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/regex-equal.d.ts +14 -0
- package/dist/src/plugins/NextFederationPlugin/regex-equal.js +25 -0
- package/dist/src/plugins/NextFederationPlugin/regex-equal.js.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.d.ts +8 -0
- package/dist/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js +34 -0
- package/dist/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/set-options.d.ts +16 -0
- package/dist/src/plugins/NextFederationPlugin/set-options.js +22 -0
- package/dist/src/plugins/NextFederationPlugin/set-options.js.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/validate-options.d.ts +25 -0
- package/dist/src/plugins/NextFederationPlugin/validate-options.js +45 -0
- package/dist/src/plugins/NextFederationPlugin/validate-options.js.map +1 -0
- package/dist/src/plugins/container/InvertedContainerPlugin.d.ts +5 -0
- package/dist/src/plugins/container/InvertedContainerPlugin.js +28 -0
- package/dist/src/plugins/container/InvertedContainerPlugin.js.map +1 -0
- package/dist/src/plugins/container/InvertedContainerRuntimeModule.d.ts +11 -0
- package/dist/src/plugins/container/InvertedContainerRuntimeModule.js +69 -0
- package/dist/src/plugins/container/InvertedContainerRuntimeModule.js.map +1 -0
- package/dist/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.d.ts +39 -0
- package/dist/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js +78 -0
- package/dist/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js.map +1 -0
- package/dist/src/plugins/container/runtimePlugin.cjs +216 -0
- package/dist/src/plugins/container/runtimePlugin.d.ts +2 -0
- package/dist/src/plugins/container/runtimePlugin.js.map +1 -0
- package/dist/src/plugins/container/types.d.ts +2 -0
- package/dist/src/plugins/container/types.js +3 -0
- package/dist/src/plugins/container/types.js.map +1 -0
- package/dist/src/types.d.ts +28 -0
- package/dist/src/types.js +3 -0
- package/dist/src/types.js.map +1 -0
- package/dist/utils/flushedChunks.d.ts +22 -0
- package/dist/utils/flushedChunks.js +77 -0
- package/dist/utils/flushedChunks.js.map +1 -0
- package/dist/utils/index.d.ts +20 -0
- package/dist/utils/index.js +66 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,100 @@
|
|
|
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.applyPathFixes = exports.retrieveDefaultShared = void 0;
|
|
7
|
+
const internal_1 = require("../../internal");
|
|
8
|
+
const helpers_1 = require("../../loaders/helpers");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
/**
|
|
11
|
+
* Set up default shared values based on the environment.
|
|
12
|
+
* @param {boolean} isServer - Boolean indicating if the code is running on the server.
|
|
13
|
+
* @returns {SharedObject} The default share scope based on the environment.
|
|
14
|
+
*/
|
|
15
|
+
const retrieveDefaultShared = (isServer) => {
|
|
16
|
+
// If the code is running on the server, treat some Next.js internals as import false to make them external
|
|
17
|
+
// This is because they will be provided by the server environment and not by the remote container
|
|
18
|
+
if (isServer) {
|
|
19
|
+
return internal_1.DEFAULT_SHARE_SCOPE;
|
|
20
|
+
}
|
|
21
|
+
// If the code is running on the client/browser, always bundle Next.js internals
|
|
22
|
+
return internal_1.DEFAULT_SHARE_SCOPE_BROWSER;
|
|
23
|
+
};
|
|
24
|
+
exports.retrieveDefaultShared = retrieveDefaultShared;
|
|
25
|
+
const applyPathFixes = (compiler, pluginOptions, options) => {
|
|
26
|
+
const match = (0, helpers_1.findLoaderForResource)(compiler.options.module.rules, {
|
|
27
|
+
path: path_1.default.join(compiler.context, '/something/thing.js'),
|
|
28
|
+
issuerLayer: undefined,
|
|
29
|
+
layer: undefined,
|
|
30
|
+
});
|
|
31
|
+
compiler.options.module.rules.forEach((rule) => {
|
|
32
|
+
if (typeof rule === 'object' && rule !== null) {
|
|
33
|
+
const typedRule = rule;
|
|
34
|
+
// next-image-loader fix which adds remote's hostname to the assets url
|
|
35
|
+
if (options.enableImageLoaderFix &&
|
|
36
|
+
(0, helpers_1.hasLoader)(typedRule, 'next-image-loader')) {
|
|
37
|
+
(0, helpers_1.injectRuleLoader)(typedRule, {
|
|
38
|
+
loader: require.resolve('../../loaders/fixImageLoader'),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (options.enableUrlLoaderFix && (0, helpers_1.hasLoader)(typedRule, 'url-loader')) {
|
|
42
|
+
(0, helpers_1.injectRuleLoader)(typedRule, {
|
|
43
|
+
loader: require.resolve('../../loaders/fixUrlLoader'),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
if (match) {
|
|
49
|
+
let matchCopy;
|
|
50
|
+
if (match.use) {
|
|
51
|
+
matchCopy = { ...match };
|
|
52
|
+
if (Array.isArray(match.use)) {
|
|
53
|
+
matchCopy.use = match.use.filter((loader) => {
|
|
54
|
+
return (typeof loader === 'object' &&
|
|
55
|
+
loader.loader &&
|
|
56
|
+
!loader.loader.includes('react'));
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else if (typeof match.use === 'string') {
|
|
60
|
+
matchCopy.use = match.use.includes('react') ? '' : match.use;
|
|
61
|
+
}
|
|
62
|
+
else if (typeof match.use === 'object' && match.use !== null) {
|
|
63
|
+
matchCopy.use =
|
|
64
|
+
match.use.loader && match.use.loader.includes('react')
|
|
65
|
+
? {}
|
|
66
|
+
: match.use;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
matchCopy = { ...match };
|
|
71
|
+
}
|
|
72
|
+
const descriptionDataRule = {
|
|
73
|
+
...matchCopy,
|
|
74
|
+
descriptionData: {
|
|
75
|
+
name: /^(@module-federation)/,
|
|
76
|
+
},
|
|
77
|
+
exclude: undefined,
|
|
78
|
+
include: undefined,
|
|
79
|
+
};
|
|
80
|
+
const testRule = {
|
|
81
|
+
...matchCopy,
|
|
82
|
+
resourceQuery: /runtimePlugin/,
|
|
83
|
+
exclude: undefined,
|
|
84
|
+
include: undefined,
|
|
85
|
+
};
|
|
86
|
+
const oneOfRule = compiler.options.module.rules.find((rule) => {
|
|
87
|
+
return !!rule && typeof rule === 'object' && 'oneOf' in rule;
|
|
88
|
+
});
|
|
89
|
+
if (!oneOfRule) {
|
|
90
|
+
compiler.options.module.rules.unshift({
|
|
91
|
+
oneOf: [descriptionDataRule, testRule],
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else if (oneOfRule.oneOf) {
|
|
95
|
+
oneOfRule.oneOf.unshift(descriptionDataRule, testRule);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
exports.applyPathFixes = applyPathFixes;
|
|
100
|
+
//# sourceMappingURL=next-fragments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-fragments.js","sourceRoot":"","sources":["../../../../src/plugins/NextFederationPlugin/next-fragments.ts"],"names":[],"mappings":";;;;;;AAKA,6CAGwB;AACxB,mDAI+B;AAC/B,gDAAwB;AACxB;;;;GAIG;AACI,MAAM,qBAAqB,GAAG,CACnC,QAAiB,EACoB,EAAE;IACvC,2GAA2G;IAC3G,kGAAkG;IAClG,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,8BAAmB,CAAC;IAC7B,CAAC;IACD,gFAAgF;IAChF,OAAO,sCAA2B,CAAC;AACrC,CAAC,CAAC;AAVW,QAAA,qBAAqB,yBAUhC;AACK,MAAM,cAAc,GAAG,CAC5B,QAAkB,EAClB,aAAmE,EACnE,OAAY,EACZ,EAAE;IACF,MAAM,KAAK,GAAG,IAAA,+BAAqB,EACjC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,KAAsB,EAC9C;QACE,IAAI,EAAE,cAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAC;QACxD,WAAW,EAAE,SAAS;QACtB,KAAK,EAAE,SAAS;KACjB,CACF,CAAC;IAEF,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC7C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAC9C,MAAM,SAAS,GAAG,IAAmB,CAAC;YACtC,uEAAuE;YACvE,IACE,OAAO,CAAC,oBAAoB;gBAC5B,IAAA,mBAAS,EAAC,SAAS,EAAE,mBAAmB,CAAC,EACzC,CAAC;gBACD,IAAA,0BAAgB,EAAC,SAAS,EAAE;oBAC1B,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,8BAA8B,CAAC;iBACxD,CAAC,CAAC;YACL,CAAC;YAED,IAAI,OAAO,CAAC,kBAAkB,IAAI,IAAA,mBAAS,EAAC,SAAS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CAAC;YACN,SAAS,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;QAC3B,CAAC;QAED,MAAM,mBAAmB,GAAgB;YACvC,GAAG,SAAS;YACZ,eAAe,EAAE;gBACf,IAAI,EAAE,uBAAuB;aAC9B;YACD,OAAO,EAAE,SAAS;YAClB,OAAO,EAAE,SAAS;SACnB,CAAC;QAEF,MAAM,QAAQ,GAAgB;YAC5B,GAAG,SAAS;YACZ,aAAa,EAAE,eAAe;YAC9B,OAAO,EAAE,SAAS;YAClB,OAAO,EAAE,SAAS;SACnB,CAAC;QAEF,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAClD,CAAC,IAAI,EAAuB,EAAE;YAC5B,OAAO,CAAC,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,IAAI,CAAC;QAC/D,CAAC,CACyB,CAAC;QAE7B,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC;gBACpC,KAAK,EAAE,CAAC,mBAAmB,EAAE,QAAQ,CAAC;aACvC,CAAC,CAAC;QACL,CAAC;aAAM,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC;YAC3B,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,mBAAmB,EAAE,QAAQ,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAzFW,QAAA,cAAc,kBAyFzB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RuleSetConditionAbsolute } from 'webpack';
|
|
2
|
+
/**
|
|
3
|
+
* Compares two regular expressions or other types of conditions to see if they are equal.
|
|
4
|
+
*
|
|
5
|
+
* @param x - The first condition to compare. It can be a string, a RegExp, a function that takes a string and returns a boolean, an array of RuleSetConditionAbsolute, or undefined.
|
|
6
|
+
* @param y - The second condition to compare. It is always a RegExp.
|
|
7
|
+
* @returns True if the conditions are equal, false otherwise.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This function compares two conditions to see if they are equal in terms of their source,
|
|
11
|
+
* global, ignoreCase, and multiline properties. It is used to check if two conditions match
|
|
12
|
+
* the same pattern. If the first condition is not a RegExp, the function will always return false.
|
|
13
|
+
*/
|
|
14
|
+
export declare const regexEqual: (x: string | RegExp | ((value: string) => boolean) | RuleSetConditionAbsolute[] | 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 or other types of conditions to see if they are equal.
|
|
6
|
+
*
|
|
7
|
+
* @param x - The first condition to compare. It can be a string, a RegExp, a function that takes a string and returns a boolean, an array of RuleSetConditionAbsolute, or undefined.
|
|
8
|
+
* @param y - The second condition to compare. It is always a RegExp.
|
|
9
|
+
* @returns True if the conditions are equal, false otherwise.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* This function compares two conditions to see if they are equal in terms of their source,
|
|
13
|
+
* global, ignoreCase, and multiline properties. It is used to check if two conditions match
|
|
14
|
+
* the same pattern. If the first condition is not a RegExp, the function will always return false.
|
|
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":["../../../../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,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function to remove unnecessary shared keys from the default share scope.
|
|
3
|
+
* It iterates over each key in the shared object and checks against the default share scope.
|
|
4
|
+
* If a key is found in the default share scope, a warning is logged and the key is removed from the shared object.
|
|
5
|
+
*
|
|
6
|
+
* @param {Record<string, unknown>} shared - The shared object to be checked.
|
|
7
|
+
*/
|
|
8
|
+
export declare function removeUnnecessarySharedKeys(shared: Record<string, unknown>): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
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.removeUnnecessarySharedKeys = removeUnnecessarySharedKeys;
|
|
7
|
+
/**
|
|
8
|
+
* Utility function to remove unnecessary shared keys from the default share scope.
|
|
9
|
+
* It checks each key in the shared object against the default share scope.
|
|
10
|
+
* If a key is found in the default share scope, a warning is logged and the key is removed from the shared object.
|
|
11
|
+
*
|
|
12
|
+
* @param {Record<string, unknown>} shared - The shared object to be checked.
|
|
13
|
+
*/
|
|
14
|
+
const internal_1 = require("../../internal");
|
|
15
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
16
|
+
/**
|
|
17
|
+
* Function to remove unnecessary shared keys from the default share scope.
|
|
18
|
+
* It iterates over each key in the shared object and checks against the default share scope.
|
|
19
|
+
* If a key is found in the default share scope, a warning is logged and the key is removed from the shared object.
|
|
20
|
+
*
|
|
21
|
+
* @param {Record<string, unknown>} shared - The shared object to be checked.
|
|
22
|
+
*/
|
|
23
|
+
function removeUnnecessarySharedKeys(shared) {
|
|
24
|
+
Object.keys(shared).forEach((key) => {
|
|
25
|
+
/**
|
|
26
|
+
* If the key is found in the default share scope, log a warning and remove the key from the shared object.
|
|
27
|
+
*/
|
|
28
|
+
if (internal_1.DEFAULT_SHARE_SCOPE[key]) {
|
|
29
|
+
logger_1.default.warn(`You are sharing ${key} from the default share scope. This is not necessary and can be removed.`);
|
|
30
|
+
delete shared[key];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=remove-unnecessary-shared-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-unnecessary-shared-keys.js","sourceRoot":"","sources":["../../../../src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.ts"],"names":[],"mappings":";;;;;AAiBA,kEAcC;AA/BD;;;;;;GAMG;AACH,6CAAqD;AACrD,0DAAkC;AAElC;;;;;;GAMG;AACH,SAAgB,2BAA2B,CACzC,MAA+B;IAE/B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE;QAC1C;;WAEG;QACH,IAAI,8BAAmB,CAAC,GAAG,CAAC,EAAE,CAAC;YAC7B,gBAAM,CAAC,IAAI,CACT,mBAAmB,GAAG,0EAA0E,CACjG,CAAC;YACF,OAAQ,MAAqC,CAAC,GAAG,CAAC,CAAC;QACrD,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
|
+
export interface NextFederationPluginExtraOptions {
|
|
3
|
+
enableImageLoaderFix?: boolean;
|
|
4
|
+
enableUrlLoaderFix?: boolean;
|
|
5
|
+
exposePages?: boolean;
|
|
6
|
+
skipSharingNextInternals?: boolean;
|
|
7
|
+
automaticPageStitching?: boolean;
|
|
8
|
+
debug?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface NextFederationPluginOptions extends moduleFederationPlugin.ModuleFederationPluginOptions {
|
|
11
|
+
extraOptions: NextFederationPluginExtraOptions;
|
|
12
|
+
}
|
|
13
|
+
export declare function setOptions(options: NextFederationPluginOptions): {
|
|
14
|
+
mainOptions: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
15
|
+
extraOptions: NextFederationPluginExtraOptions;
|
|
16
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setOptions = setOptions;
|
|
4
|
+
function setOptions(options) {
|
|
5
|
+
const { extraOptions, ...mainOpts } = options;
|
|
6
|
+
/**
|
|
7
|
+
* Default extra options for NextFederationPlugin.
|
|
8
|
+
* @type {NextFederationPluginExtraOptions}
|
|
9
|
+
*/
|
|
10
|
+
const defaultExtraOptions = {
|
|
11
|
+
automaticPageStitching: false,
|
|
12
|
+
enableImageLoaderFix: false,
|
|
13
|
+
enableUrlLoaderFix: false,
|
|
14
|
+
skipSharingNextInternals: false,
|
|
15
|
+
debug: false,
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
mainOptions: mainOpts,
|
|
19
|
+
extraOptions: { ...defaultExtraOptions, ...extraOptions },
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=set-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-options.js","sourceRoot":"","sources":["../../../../src/plugins/NextFederationPlugin/set-options.ts"],"names":[],"mappings":";;AAgBA,gCAsBC;AAtBD,SAAgB,UAAU,CAAC,OAAoC;IAI7D,MAAM,EAAE,YAAY,EAAE,GAAG,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE9C;;;OAGG;IACH,MAAM,mBAAmB,GAAqC;QAC5D,sBAAsB,EAAE,KAAK;QAC7B,oBAAoB,EAAE,KAAK;QAC3B,kBAAkB,EAAE,KAAK;QACzB,wBAAwB,EAAE,KAAK;QAC/B,KAAK,EAAE,KAAK;KACb,CAAC;IAEF,OAAO;QACL,WAAW,EAAE,QAAQ;QACrB,YAAY,EAAE,EAAE,GAAG,mBAAmB,EAAE,GAAG,YAAY,EAAE;KAC1D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Compiler } from 'webpack';
|
|
2
|
+
import type { moduleFederationPlugin } from '@module-federation/sdk';
|
|
3
|
+
/**
|
|
4
|
+
* Validates the compiler options.
|
|
5
|
+
*
|
|
6
|
+
* @param {Compiler} compiler - The Webpack compiler instance.
|
|
7
|
+
* @returns {boolean} - Returns true if the compiler options are valid, false otherwise.
|
|
8
|
+
*
|
|
9
|
+
* @throws Will throw an error if the name option is not defined in the options.
|
|
10
|
+
* @remarks
|
|
11
|
+
* This function validates the options passed to the Webpack compiler. It 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
|
+
* Validates the NextFederationPlugin options.
|
|
17
|
+
*
|
|
18
|
+
* @param {moduleFederationPlugin.ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
|
|
19
|
+
*
|
|
20
|
+
* @throws Will throw an error if the filename option is not defined in the options or if the name option is not specified.
|
|
21
|
+
* @remarks
|
|
22
|
+
* This function validates the options passed to NextFederationPlugin. It ensures that the filename and name options are defined,
|
|
23
|
+
* as they are required for using Module Federation.
|
|
24
|
+
*/
|
|
25
|
+
export declare function validatePluginOptions(options: moduleFederationPlugin.ModuleFederationPluginOptions): boolean | void;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateCompilerOptions = validateCompilerOptions;
|
|
4
|
+
exports.validatePluginOptions = validatePluginOptions;
|
|
5
|
+
/**
|
|
6
|
+
* Validates the compiler options.
|
|
7
|
+
*
|
|
8
|
+
* @param {Compiler} compiler - The Webpack compiler instance.
|
|
9
|
+
* @returns {boolean} - Returns true if the compiler options are valid, false otherwise.
|
|
10
|
+
*
|
|
11
|
+
* @throws Will throw an error if the name option is not defined in the options.
|
|
12
|
+
* @remarks
|
|
13
|
+
* This function validates the options passed to the Webpack compiler. It checks if the name option is set to either "server" or
|
|
14
|
+
* "client", as Module Federation is only applied to the main server and client builds in Next.js.
|
|
15
|
+
*/
|
|
16
|
+
function validateCompilerOptions(compiler) {
|
|
17
|
+
// Throw an error if the name option is not defined in the options
|
|
18
|
+
if (!compiler.options.name) {
|
|
19
|
+
throw new Error('name is not defined in Compiler options');
|
|
20
|
+
}
|
|
21
|
+
// Only apply Module Federation to the main server and client builds in Next.js
|
|
22
|
+
return ['server', 'client'].includes(compiler.options.name);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validates the NextFederationPlugin options.
|
|
26
|
+
*
|
|
27
|
+
* @param {moduleFederationPlugin.ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
|
|
28
|
+
*
|
|
29
|
+
* @throws Will throw an error if the filename option is not defined in the options or if the name option is not specified.
|
|
30
|
+
* @remarks
|
|
31
|
+
* This function validates the options passed to NextFederationPlugin. It ensures that the filename and name options are defined,
|
|
32
|
+
* as they are required for using Module Federation.
|
|
33
|
+
*/
|
|
34
|
+
function validatePluginOptions(options) {
|
|
35
|
+
// Throw an error if the filename option is not defined in the options
|
|
36
|
+
if (!options.filename) {
|
|
37
|
+
throw new Error('filename is not defined in NextFederation options');
|
|
38
|
+
}
|
|
39
|
+
// A requirement for using Module Federation is that a name must be specified
|
|
40
|
+
if (!options.name) {
|
|
41
|
+
throw new Error('Module federation "name" option must be specified');
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=validate-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-options.js","sourceRoot":"","sources":["../../../../src/plugins/NextFederationPlugin/validate-options.ts"],"names":[],"mappings":";;AAcA,0DAQC;AAYD,sDAaC;AA5CD;;;;;;;;;;GAUG;AACH,SAAgB,uBAAuB,CAAC,QAAkB;IACxD,kEAAkE;IAClE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IAED,+EAA+E;IAC/E,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,qBAAqB,CACnC,OAA6D;IAE7D,sEAAsE;IACtE,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IAED,6EAA6E;IAC7E,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 InvertedContainerRuntimeModule_1 = __importDefault(require("./InvertedContainerRuntimeModule"));
|
|
7
|
+
const enhanced_1 = require("@module-federation/enhanced");
|
|
8
|
+
class InvertedContainerPlugin {
|
|
9
|
+
apply(compiler) {
|
|
10
|
+
compiler.hooks.thisCompilation.tap('EmbeddedContainerPlugin', (compilation) => {
|
|
11
|
+
const hooks = enhanced_1.FederationModulesPlugin.getCompilationHooks(compilation);
|
|
12
|
+
const containers = new Set();
|
|
13
|
+
hooks.addContainerEntryDependency.tap('EmbeddedContainerPlugin', (dependency) => {
|
|
14
|
+
if (dependency instanceof enhanced_1.dependencies.ContainerEntryDependency) {
|
|
15
|
+
containers.add(dependency);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
// Adding the runtime module
|
|
19
|
+
compilation.hooks.additionalTreeRuntimeRequirements.tap('EmbeddedContainerPlugin', (chunk, set) => {
|
|
20
|
+
compilation.addRuntimeModule(chunk, new InvertedContainerRuntimeModule_1.default({
|
|
21
|
+
containers,
|
|
22
|
+
}));
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.default = InvertedContainerPlugin;
|
|
28
|
+
//# sourceMappingURL=InvertedContainerPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InvertedContainerPlugin.js","sourceRoot":"","sources":["../../../../src/plugins/container/InvertedContainerPlugin.ts"],"names":[],"mappings":";;;;;AACA,sGAA8E;AAC9E,0DAGqC;AAErC,MAAM,uBAAuB;IACpB,KAAK,CAAC,QAAkB;QAC7B,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAChC,yBAAyB,EACzB,CAAC,WAAwB,EAAE,EAAE;YAC3B,MAAM,KAAK,GAAG,kCAAuB,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;YACvE,MAAM,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;YAC7B,KAAK,CAAC,2BAA2B,CAAC,GAAG,CACnC,yBAAyB,EACzB,CAAC,UAAU,EAAE,EAAE;gBACb,IAAI,UAAU,YAAY,uBAAY,CAAC,wBAAwB,EAAE,CAAC;oBAChE,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;gBAC7B,CAAC;YACH,CAAC,CACF,CAAC;YACF,4BAA4B;YAC5B,WAAW,CAAC,KAAK,CAAC,iCAAiC,CAAC,GAAG,CACrD,yBAAyB,EACzB,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;gBACb,WAAW,CAAC,gBAAgB,CAC1B,KAAK,EACL,IAAI,wCAA8B,CAAC;oBACjC,UAAU;iBACX,CAAC,CACH,CAAC;YACJ,CAAC,CACF,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAED,kBAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const RuntimeModule: typeof import("webpack").RuntimeModule;
|
|
2
|
+
interface InvertedContainerRuntimeModuleOptions {
|
|
3
|
+
name?: string;
|
|
4
|
+
containers: Set<any>;
|
|
5
|
+
}
|
|
6
|
+
declare class InvertedContainerRuntimeModule extends RuntimeModule {
|
|
7
|
+
private options;
|
|
8
|
+
constructor(options: InvertedContainerRuntimeModuleOptions);
|
|
9
|
+
generate(): string;
|
|
10
|
+
}
|
|
11
|
+
export default InvertedContainerRuntimeModule;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
|
|
4
|
+
const { RuntimeModule, Template, RuntimeGlobals } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
|
|
5
|
+
class InvertedContainerRuntimeModule extends RuntimeModule {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super('inverted container startup', RuntimeModule.STAGE_TRIGGER);
|
|
8
|
+
this.options = options;
|
|
9
|
+
}
|
|
10
|
+
generate() {
|
|
11
|
+
const { compilation, chunk, chunkGraph } = this;
|
|
12
|
+
if (!compilation || !chunk || !chunkGraph) {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
if (chunk.runtime === 'webpack-api-runtime') {
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
const runtimeChunk = compilation.options.optimization?.runtimeChunk;
|
|
19
|
+
if (runtimeChunk === 'single' || typeof runtimeChunk === 'object') {
|
|
20
|
+
const logger = compilation.getLogger('InvertedContainerRuntimeModule');
|
|
21
|
+
logger.info('Runtime chunk is set to single. Consider adding runtime: false to your ModuleFederationPlugin configuration to prevent runtime conflicts.');
|
|
22
|
+
}
|
|
23
|
+
let containerEntryModule;
|
|
24
|
+
for (const containerDep of this.options.containers) {
|
|
25
|
+
const mod = compilation.moduleGraph.getModule(containerDep);
|
|
26
|
+
if (!mod)
|
|
27
|
+
continue;
|
|
28
|
+
if (chunkGraph.isModuleInChunk(mod, chunk)) {
|
|
29
|
+
containerEntryModule = mod;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (!containerEntryModule)
|
|
33
|
+
return '';
|
|
34
|
+
if (compilation.chunkGraph.isEntryModuleInChunk(containerEntryModule, chunk)) {
|
|
35
|
+
// Don't apply to the remote entry itself
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
const initRuntimeModuleGetter = compilation.runtimeTemplate.moduleRaw({
|
|
39
|
+
module: containerEntryModule,
|
|
40
|
+
chunkGraph,
|
|
41
|
+
weak: false,
|
|
42
|
+
runtimeRequirements: new Set(),
|
|
43
|
+
});
|
|
44
|
+
//@ts-ignore
|
|
45
|
+
const nameJSON = JSON.stringify(containerEntryModule._name);
|
|
46
|
+
return Template.asString([
|
|
47
|
+
`var prevStartup = ${RuntimeGlobals.startup};`,
|
|
48
|
+
`var hasRun = false;`,
|
|
49
|
+
`var cachedRemote;`,
|
|
50
|
+
`${RuntimeGlobals.startup} = ${compilation.runtimeTemplate.basicFunction('', Template.asString([
|
|
51
|
+
`if (!hasRun) {`,
|
|
52
|
+
Template.indent(Template.asString([
|
|
53
|
+
`hasRun = true;`,
|
|
54
|
+
`if (typeof prevStartup === 'function') {`,
|
|
55
|
+
Template.indent(Template.asString([`prevStartup();`])),
|
|
56
|
+
`}`,
|
|
57
|
+
`cachedRemote = ${initRuntimeModuleGetter};`,
|
|
58
|
+
`var gs = ${RuntimeGlobals.global} || globalThis;`,
|
|
59
|
+
`gs[${nameJSON}] = cachedRemote;`,
|
|
60
|
+
])),
|
|
61
|
+
`} else if (typeof prevStartup === 'function') {`,
|
|
62
|
+
Template.indent(`prevStartup();`),
|
|
63
|
+
`}`,
|
|
64
|
+
]))};`,
|
|
65
|
+
]);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.default = InvertedContainerRuntimeModule;
|
|
69
|
+
//# sourceMappingURL=InvertedContainerRuntimeModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InvertedContainerRuntimeModule.js","sourceRoot":"","sources":["../../../../src/plugins/container/InvertedContainerRuntimeModule.ts"],"names":[],"mappings":";;AAAA,0FAAqF;AAErF,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,OAAO,CACzD,IAAA,6CAAoB,EAAC,SAAS,CAAC,CACJ,CAAC;AAO9B,MAAM,8BAA+B,SAAQ,aAAa;IAGxD,YAAY,OAA8C;QACxD,KAAK,CAAC,4BAA4B,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;QACjE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEQ,QAAQ;QACf,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;QAChD,IAAI,CAAC,WAAW,IAAI,CAAC,KAAK,IAAI,CAAC,UAAU,EAAE,CAAC;YAC1C,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,KAA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AqB;YACrB,mBAAmB;YACnB,GAAG,cAAc,CAAC,OAAO,MAAM,WAAW,CAAC,eAAe,CAAC,aAAa,CACtE,EAAE,EACF,QAAQ,CAAC,QAAQ,CAAC;gBAChB,gBAAgB;gBAChB,QAAQ,CAAC,MAAM,CACb,QAAQ,CAAC,QAAQ,CAAC;oBAChB,gBAAgB;oBAChB,0CAA0C;oBAC1C,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC;oBACtD,GAAG;oBACH,kBAAkB,uBAAuB,GAAG;oBAC5C,YAAY,cAAc,CAAC,MAAM,iBAAiB;oBAClD,MAAM,QAAQ,mBAAmB;iBAClC,CAAC,CACH;gBACD,iDAAiD;gBACjD,QAAQ,CAAC,MAAM,CAAC,gBAAgB,CAAC;gBACjC,GAAG;aACJ,CAAC,CACH,GAAG;SACL,CAAC,CAAC;IACL,CAAC;CACF;AAED,kBAAe,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Compiler } from 'webpack';
|
|
2
|
+
/**
|
|
3
|
+
* This plugin removes eager modules from the runtime.
|
|
4
|
+
* @class RemoveEagerModulesFromRuntimePlugin
|
|
5
|
+
*/
|
|
6
|
+
declare class RemoveEagerModulesFromRuntimePlugin {
|
|
7
|
+
private container;
|
|
8
|
+
private debug;
|
|
9
|
+
private modulesToProcess;
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of RemoveEagerModulesFromRuntimePlugin.
|
|
12
|
+
* @param {Object} options - The options for the plugin.
|
|
13
|
+
* @param {string} options.container - The container to remove modules from.
|
|
14
|
+
* @param {boolean} options.debug - Whether to log debug information.
|
|
15
|
+
*/
|
|
16
|
+
constructor(options: {
|
|
17
|
+
container?: string;
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Applies the plugin to the compiler.
|
|
22
|
+
* @param {Compiler} compiler - The webpack compiler.
|
|
23
|
+
*/
|
|
24
|
+
apply(compiler: Compiler): void;
|
|
25
|
+
/**
|
|
26
|
+
* Processes the modules in the chunk.
|
|
27
|
+
* @param {Compilation} compilation - The webpack compilation.
|
|
28
|
+
* @param {Chunk} chunk - The chunk to process.
|
|
29
|
+
* @param {Iterable<Module>} modules - The modules in the chunk.
|
|
30
|
+
*/
|
|
31
|
+
private processModules;
|
|
32
|
+
/**
|
|
33
|
+
* Removes the modules from the chunk.
|
|
34
|
+
* @param {Compilation} compilation - The webpack compilation.
|
|
35
|
+
* @param {Chunk} chunk - The chunk to remove modules from.
|
|
36
|
+
*/
|
|
37
|
+
private removeModules;
|
|
38
|
+
}
|
|
39
|
+
export default RemoveEagerModulesFromRuntimePlugin;
|
|
@@ -0,0 +1,78 @@
|
|
|
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 sdk_1 = require("@module-federation/sdk");
|
|
7
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
8
|
+
/**
|
|
9
|
+
* This plugin removes eager modules from the runtime.
|
|
10
|
+
* @class RemoveEagerModulesFromRuntimePlugin
|
|
11
|
+
*/
|
|
12
|
+
class RemoveEagerModulesFromRuntimePlugin {
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of RemoveEagerModulesFromRuntimePlugin.
|
|
15
|
+
* @param {Object} options - The options for the plugin.
|
|
16
|
+
* @param {string} options.container - The container to remove modules from.
|
|
17
|
+
* @param {boolean} options.debug - Whether to log debug information.
|
|
18
|
+
*/
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.container = options.container;
|
|
21
|
+
this.debug = options.debug || false;
|
|
22
|
+
this.modulesToProcess = new Set();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Applies the plugin to the compiler.
|
|
26
|
+
* @param {Compiler} compiler - The webpack compiler.
|
|
27
|
+
*/
|
|
28
|
+
apply(compiler) {
|
|
29
|
+
if (!this.container) {
|
|
30
|
+
logger_1.default.warn(`RemoveEagerModulesFromRuntimePlugin container is not defined: ${this.container}`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
(0, sdk_1.bindLoggerToCompiler)(logger_1.default, compiler, 'RemoveEagerModulesFromRuntimePlugin');
|
|
34
|
+
compiler.hooks.thisCompilation.tap('RemoveEagerModulesFromRuntimePlugin', (compilation) => {
|
|
35
|
+
compilation.hooks.optimizeChunkModules.tap('RemoveEagerModulesFromRuntimePlugin', (chunks, modules) => {
|
|
36
|
+
for (const chunk of chunks) {
|
|
37
|
+
if (chunk.hasRuntime() && chunk.name === this.container) {
|
|
38
|
+
this.processModules(compilation, chunk, modules);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Processes the modules in the chunk.
|
|
46
|
+
* @param {Compilation} compilation - The webpack compilation.
|
|
47
|
+
* @param {Chunk} chunk - The chunk to process.
|
|
48
|
+
* @param {Iterable<Module>} modules - The modules in the chunk.
|
|
49
|
+
*/
|
|
50
|
+
processModules(compilation, chunk, modules) {
|
|
51
|
+
for (const module of modules) {
|
|
52
|
+
if (!compilation.chunkGraph.isModuleInChunk(module, chunk)) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (module.constructor.name === 'NormalModule') {
|
|
56
|
+
this.modulesToProcess.add(module);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
this.removeModules(compilation, chunk);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Removes the modules from the chunk.
|
|
63
|
+
* @param {Compilation} compilation - The webpack compilation.
|
|
64
|
+
* @param {Chunk} chunk - The chunk to remove modules from.
|
|
65
|
+
*/
|
|
66
|
+
removeModules(compilation, chunk) {
|
|
67
|
+
for (const moduleToRemove of this.modulesToProcess) {
|
|
68
|
+
if (this.debug) {
|
|
69
|
+
logger_1.default.info(`removing ${moduleToRemove.constructor.name}`);
|
|
70
|
+
}
|
|
71
|
+
if (compilation.chunkGraph.isModuleInChunk(moduleToRemove, chunk)) {
|
|
72
|
+
compilation.chunkGraph.disconnectChunkAndModule(chunk, moduleToRemove);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.default = RemoveEagerModulesFromRuntimePlugin;
|
|
78
|
+
//# sourceMappingURL=RemoveEagerModulesFromRuntimePlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoveEagerModulesFromRuntimePlugin.js","sourceRoot":"","sources":["../../../../src/plugins/container/RemoveEagerModulesFromRuntimePlugin.ts"],"names":[],"mappings":";;;;;AACA,gDAA8D;AAC9D,0DAAkC;AAElC;;;GAGG;AACH,MAAM,mCAAmC;IAKvC;;;;;OAKG;IACH,YAAY,OAAgD;QAC1D,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC;QACpC,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;IAC5C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAkB;QACtB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,gBAAM,CAAC,IAAI,CACT,iEAAiE,IAAI,CAAC,SAAS,EAAE,CAClF,CAAC;YACF,OAAO;QACT,CAAC;QAED,IAAA,0BAAoB,EAClB,gBAAM,EACN,QAAQ,EACR,qCAAqC,CACtC,CAAC;QAEF,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAChC,qCAAqC,EACrC,CAAC,WAAwB,EAAE,EAAE;YAC3B,WAAW,CAAC,KAAK,CAAC,oBAAoB,CAAC,GAAG,CACxC,qCA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