@sima-land/isomorph 10.0.0 → 10.1.0
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/module-federation/__example__/webpack-config.example.js +8 -1
- package/module-federation/__example__/webpack-config.example.js.map +1 -1
- package/module-federation/enhanced-module-federation-plugin.d.ts +27 -4
- package/module-federation/enhanced-module-federation-plugin.js +30 -5
- package/module-federation/enhanced-module-federation-plugin.js.map +1 -1
- package/module-federation/utils/index.d.ts +12 -4
- package/module-federation/utils/index.js +10 -5
- package/module-federation/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/module-federation/__example__/webpack-config.example.js +8 -1
- package/src/module-federation/enhanced-module-federation-plugin.js +34 -7
- package/src/module-federation/utils/index.js +14 -7
|
@@ -30,7 +30,14 @@ const HostServiceConfig = {
|
|
|
30
30
|
new ExtendedMFPlugin({
|
|
31
31
|
name: 'host-service-name',
|
|
32
32
|
remotes: {
|
|
33
|
-
|
|
33
|
+
firstRemoteService: 'first-remote-service-name',
|
|
34
|
+
secondRemoteService: {
|
|
35
|
+
name: 'second-remote-service-name', // Путь к remote entry определяется в рантайме
|
|
36
|
+
},
|
|
37
|
+
thirdRemoteService: {
|
|
38
|
+
name: 'third-remote-service-name',
|
|
39
|
+
remoteEntryPath: '//path/to/remoteEntry.js', // Путь к remote entry задан явно
|
|
40
|
+
},
|
|
34
41
|
},
|
|
35
42
|
}),
|
|
36
43
|
],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpack-config.example.js","sourceRoot":"","sources":["../../../src/module-federation/__example__/webpack-config.example.js"],"names":[],"mappings":";AAAA;;GAEG;AACH,MAAM,gBAAgB,GAAG,OAAO,CAAC,sCAAsC,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,mBAAmB,GAAG;IAC1B,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa;IAC1E,OAAO,EAAE;QACP,IAAI,gBAAgB,CAClB;YACE,IAAI,EAAE,qBAAqB;YAC3B,QAAQ,EACJ,uBAAuB,OAAO,CAAC,GAAG,CAAC,kBAAkB,gBAAgB,OAAO,CAAC,GAAG,CAAC,mBAAmB,KAAK;YAC7G,OAAO,EAAE;gBACP,SAAS,EAAE,yBAAyB;gBACpC,UAAU,EAAE,wBAAwB;aACrC;SACF,CACF;KACF;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,iBAAiB,GAAG;IACxB,KAAK,EAAE,gBAAgB;IACvB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa;IAC1E,OAAO,EAAE;QACP,IAAI,gBAAgB,CAClB;YACE,IAAI,EAAE,mBAAmB;YACzB,OAAO,EAAE;gBACP,
|
|
1
|
+
{"version":3,"file":"webpack-config.example.js","sourceRoot":"","sources":["../../../src/module-federation/__example__/webpack-config.example.js"],"names":[],"mappings":";AAAA;;GAEG;AACH,MAAM,gBAAgB,GAAG,OAAO,CAAC,sCAAsC,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,mBAAmB,GAAG;IAC1B,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa;IAC1E,OAAO,EAAE;QACP,IAAI,gBAAgB,CAClB;YACE,IAAI,EAAE,qBAAqB;YAC3B,QAAQ,EACJ,uBAAuB,OAAO,CAAC,GAAG,CAAC,kBAAkB,gBAAgB,OAAO,CAAC,GAAG,CAAC,mBAAmB,KAAK;YAC7G,OAAO,EAAE;gBACP,SAAS,EAAE,yBAAyB;gBACpC,UAAU,EAAE,wBAAwB;aACrC;SACF,CACF;KACF;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,iBAAiB,GAAG;IACxB,KAAK,EAAE,gBAAgB;IACvB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa;IAC1E,OAAO,EAAE;QACP,IAAI,gBAAgB,CAClB;YACE,IAAI,EAAE,mBAAmB;YACzB,OAAO,EAAE;gBACP,kBAAkB,EAAE,2BAA2B;gBAC/C,mBAAmB,EAAE;oBACnB,IAAI,EAAE,4BAA4B,EAAE,8CAA8C;iBACnF;gBACD,kBAAkB,EAAE;oBAClB,IAAI,EAAE,2BAA2B;oBACjC,eAAe,EAAE,0BAA0B,EAAE,iCAAiC;iBAC/E;aACF;SACF,CACF;KACF;IACD,OAAO,EAAE;QACP;;WAEG;QACH,QAAQ,EAAE;YACR,qBAAqB,EAAE,mCAAmC;YAC1D,sBAAsB,EAAE,mCAAmC;SAC5D;KACF;CACF,CAAC;AAEF,MAAM,CAAC,OAAO,GAAG;IACf,mBAAmB;IACnB,iBAAiB;CAClB,CAAC"}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
export = EnhancedModuleFederationPlugin;
|
|
2
|
-
/** @typedef {string}
|
|
2
|
+
/** @typedef {string} RemoteName Имя удаленного сервиса (обычно совпадает с именем в git). */
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {Object} RemoteProperty Опции подключения удаленного сервиса.
|
|
5
|
+
* @property {RemoteName} name Имя удаленного сервиса.
|
|
6
|
+
* @property {string} remoteEntryPath Статический путь к remoteEntry удаленного сервиса.
|
|
7
|
+
* @property {string} [version] Версия удаленного сервиса в формате semver.
|
|
8
|
+
*/
|
|
3
9
|
/** @typedef {import('webpack').ModuleFederationPluginOptions} MFPluginOriginalOptions Опции. */
|
|
4
10
|
/**
|
|
5
11
|
* @typedef EnhancedModuleFederationPluginOptions Опции.
|
|
6
12
|
* @param {string} name Имя сервиса.
|
|
7
13
|
* @param {string} filename Имя удаленной точки входа.
|
|
8
|
-
* @param {Object<string,
|
|
14
|
+
* @param {Object<string, RemoteName | RemoteProperty>} [remotes] Удаленные сервисы.
|
|
9
15
|
* @param {MFPluginOriginalOptions.exposes} [exposes] Предоставляемые сервисы.
|
|
10
16
|
* @param {MFPluginOriginalOptions.shared} [shared] Общие зависимости.
|
|
11
17
|
* @param {string} [remoteEntriesGlobalKey = '__RemoteEntriesList__'] Ключ свойства в глобальном объекте,
|
|
@@ -30,12 +36,29 @@ declare class EnhancedModuleFederationPlugin {
|
|
|
30
36
|
apply(compiler: import('webpack').Compiler): void;
|
|
31
37
|
}
|
|
32
38
|
declare namespace EnhancedModuleFederationPlugin {
|
|
33
|
-
export {
|
|
39
|
+
export { RemoteName, RemoteProperty, MFPluginOriginalOptions, EnhancedModuleFederationPluginOptions };
|
|
34
40
|
}
|
|
35
41
|
/**
|
|
36
42
|
* Имя удаленного сервиса (обычно совпадает с именем в git).
|
|
37
43
|
*/
|
|
38
|
-
type
|
|
44
|
+
type RemoteName = string;
|
|
45
|
+
/**
|
|
46
|
+
* Опции подключения удаленного сервиса.
|
|
47
|
+
*/
|
|
48
|
+
type RemoteProperty = {
|
|
49
|
+
/**
|
|
50
|
+
* Имя удаленного сервиса.
|
|
51
|
+
*/
|
|
52
|
+
name: RemoteName;
|
|
53
|
+
/**
|
|
54
|
+
* Статический путь к remoteEntry удаленного сервиса.
|
|
55
|
+
*/
|
|
56
|
+
remoteEntryPath: string;
|
|
57
|
+
/**
|
|
58
|
+
* Версия удаленного сервиса в формате semver.
|
|
59
|
+
*/
|
|
60
|
+
version?: string | undefined;
|
|
61
|
+
};
|
|
39
62
|
/**
|
|
40
63
|
* Опции.
|
|
41
64
|
*/
|
|
@@ -18,13 +18,24 @@ const LIBRARY_ERROR_TEXT = [
|
|
|
18
18
|
'For override global variable name use "containersGlobalKey" property.',
|
|
19
19
|
'For override "library" type use ModuleFederationPlugin.',
|
|
20
20
|
].join(' ');
|
|
21
|
-
|
|
21
|
+
const REMOTE_ERROR_TEXT = [
|
|
22
|
+
'The value of the remote element must be a string,',
|
|
23
|
+
'or an object with field `name` for dynamic resolution of `remoteEntry`.',
|
|
24
|
+
'Set `remoteEntryPath` field to object for a static path to `remoteEntry`.',
|
|
25
|
+
].join(' ');
|
|
26
|
+
/** @typedef {string} RemoteName Имя удаленного сервиса (обычно совпадает с именем в git). */
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {Object} RemoteProperty Опции подключения удаленного сервиса.
|
|
29
|
+
* @property {RemoteName} name Имя удаленного сервиса.
|
|
30
|
+
* @property {string} remoteEntryPath Статический путь к remoteEntry удаленного сервиса.
|
|
31
|
+
* @property {string} [version] Версия удаленного сервиса в формате semver.
|
|
32
|
+
*/
|
|
22
33
|
/** @typedef {import('webpack').ModuleFederationPluginOptions} MFPluginOriginalOptions Опции. */
|
|
23
34
|
/**
|
|
24
35
|
* @typedef EnhancedModuleFederationPluginOptions Опции.
|
|
25
36
|
* @param {string} name Имя сервиса.
|
|
26
37
|
* @param {string} filename Имя удаленной точки входа.
|
|
27
|
-
* @param {Object<string,
|
|
38
|
+
* @param {Object<string, RemoteName | RemoteProperty>} [remotes] Удаленные сервисы.
|
|
28
39
|
* @param {MFPluginOriginalOptions.exposes} [exposes] Предоставляемые сервисы.
|
|
29
40
|
* @param {MFPluginOriginalOptions.shared} [shared] Общие зависимости.
|
|
30
41
|
* @param {string} [remoteEntriesGlobalKey = '__RemoteEntriesList__'] Ключ свойства в глобальном объекте,
|
|
@@ -42,10 +53,17 @@ class EnhancedModuleFederationPlugin {
|
|
|
42
53
|
* @param {EnhancedModuleFederationPluginOptions} options Опции.
|
|
43
54
|
*/
|
|
44
55
|
constructor(options) {
|
|
45
|
-
const { name, library, remoteEntriesGlobalKey = '__RemoteEntriesList__', containersGlobalKey = '__FederationContainers__', } = options;
|
|
56
|
+
const { name, library, remotes, remoteEntriesGlobalKey = '__RemoteEntriesList__', containersGlobalKey = '__FederationContainers__', } = options;
|
|
46
57
|
if (library) {
|
|
47
58
|
throw new WebpackError(LIBRARY_ERROR_TEXT);
|
|
48
59
|
}
|
|
60
|
+
if (remotes) {
|
|
61
|
+
Object.values(remotes).forEach(value => {
|
|
62
|
+
if (typeof value !== 'string' && !(value === null || value === void 0 ? void 0 : value.name)) {
|
|
63
|
+
throw new WebpackError(REMOTE_ERROR_TEXT);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
49
67
|
this._options = Object.assign(Object.assign({}, options), { remoteEntriesGlobalKey,
|
|
50
68
|
containersGlobalKey, library: {
|
|
51
69
|
type: 'global',
|
|
@@ -58,8 +76,15 @@ class EnhancedModuleFederationPlugin {
|
|
|
58
76
|
apply(compiler) {
|
|
59
77
|
const _a = this._options, { remotes, remoteEntriesGlobalKey, containersGlobalKey, useInDevelopment = false } = _a, originalOptions = __rest(_a, ["remotes", "remoteEntriesGlobalKey", "containersGlobalKey", "useInDevelopment"]);
|
|
60
78
|
const configuredRemotes = {};
|
|
61
|
-
remotes && Object.
|
|
62
|
-
|
|
79
|
+
remotes && Object.entries(remotes).forEach(([key, value]) => {
|
|
80
|
+
const serviceName = (value === null || value === void 0 ? void 0 : value.name) || value;
|
|
81
|
+
const remoteEntryPath = value === null || value === void 0 ? void 0 : value.remoteEntryPath;
|
|
82
|
+
configuredRemotes[key] = { external: createExternalConfig({
|
|
83
|
+
serviceName,
|
|
84
|
+
remoteEntryPath,
|
|
85
|
+
remoteEntriesGlobalKey,
|
|
86
|
+
containersGlobalKey,
|
|
87
|
+
}) };
|
|
63
88
|
});
|
|
64
89
|
compiler.hooks.environment.tap('EnhancedModuleFederationPlugin', () => {
|
|
65
90
|
if (useInDevelopment || compiler.options.mode === 'production') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enhanced-module-federation-plugin.js","sourceRoot":"","sources":["../../src/module-federation/enhanced-module-federation-plugin.js"],"names":[],"mappings":";;;;;;;;;;;;AAAA,MAAM,EAAE,sBAAsB,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC;AAChE,MAAM,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC;AACrD,MAAM,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAEpD,MAAM,kBAAkB,GAAG;IACzB,mEAAmE;IACnE,uEAAuE;IACvE,yDAAyD;CAC1D,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEZ,
|
|
1
|
+
{"version":3,"file":"enhanced-module-federation-plugin.js","sourceRoot":"","sources":["../../src/module-federation/enhanced-module-federation-plugin.js"],"names":[],"mappings":";;;;;;;;;;;;AAAA,MAAM,EAAE,sBAAsB,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC;AAChE,MAAM,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC;AACrD,MAAM,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAEpD,MAAM,kBAAkB,GAAG;IACzB,mEAAmE;IACnE,uEAAuE;IACvE,yDAAyD;CAC1D,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEZ,MAAM,iBAAiB,GAAG;IACxB,mDAAmD;IACnD,yEAAyE;IACzE,2EAA2E;CAC5E,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEZ,6FAA6F;AAE7F;;;;;GAKG;AAEH,gGAAgG;AAEhG;;;;;;;;;;;;GAYG;AAEH;;;GAGG;AACH,MAAM,8BAA8B;IAClC;;OAEG;IACH,YAAa,OAAO;QAClB,MAAM,EACJ,IAAI,EACJ,OAAO,EACP,OAAO,EACP,sBAAsB,GAAG,uBAAuB,EAChD,mBAAmB,GAAG,0BAA0B,GACjD,GAAG,OAAO,CAAC;QAEZ,IAAI,OAAO,EAAE;YACX,MAAM,IAAI,YAAY,CAAC,kBAAkB,CAAC,CAAC;SAC5C;QAED,IAAI,OAAO,EAAE;YACX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBACrC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,CAAA,EAAE;oBAC7C,MAAM,IAAI,YAAY,CAAC,iBAAiB,CAAC,CAAC;iBAC3C;YACH,CAAC,CAAC,CAAC;SACJ;QAED,IAAI,CAAC,QAAQ,mCACR,OAAO,KACV,sBAAsB;YACtB,mBAAmB,EACnB,OAAO,EAAE;gBACP,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,CAAC,mBAAmB,EAAE,IAAI,CAAC;aAClC,GACF,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAE,QAAQ;QACb,MAAM,KAMF,IAAI,CAAC,QAAQ,EANX,EACJ,OAAO,EACP,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,GAAG,KAAK,OAET,EADZ,eAAe,cALd,gFAML,CAAgB,CAAC;QAElB,MAAM,iBAAiB,GAAG,EAAE,CAAC;QAE7B,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC1D,MAAM,WAAW,GAAG,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,KAAI,KAAK,CAAC;YACzC,MAAM,eAAe,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,eAAe,CAAC;YAE/C,iBAAiB,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,EAAE,oBAAoB,CAAC;oBACxD,WAAW;oBACX,eAAe;oBACf,sBAAsB;oBACtB,mBAAmB;iBACpB,CAAC,EAAE,CAAC;QACP,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,gCAAgC,EAAE,GAAG,EAAE;YACpE,IAAI,gBAAgB,IAAI,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,YAAY,EAAE;gBAC9D,IAAI,sBAAsB,iCACrB,OAAO,IAAI,EAAE,OAAO,EAAE,iBAAiB,EAAE,GACzC,eAAe,EAClB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;aACpB;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,CAAC,OAAO,GAAG,8BAA8B,CAAC"}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Возвращает скрипт инициализации удаленного модуля.
|
|
3
|
-
* @param {
|
|
4
|
-
* @param {string}
|
|
5
|
-
* @param {string}
|
|
3
|
+
* @param {Object} params Параметры.
|
|
4
|
+
* @param {string} params.serviceName Имя сервиса, содержащего удаленные модули.
|
|
5
|
+
* @param {string} params.remoteEntriesGlobalKey Глобальная переменная,
|
|
6
|
+
* в которой хранятся пути к удаленным точкам входа.
|
|
7
|
+
* @param {string} params.containersGlobalKey Глобальная переменная, в которую добавляются удаленные контейнеры.
|
|
8
|
+
* @param {string} params.remoteEntryPath Путь к remoteEntry, если его не надо получать в рантайме.
|
|
6
9
|
* @return {string} Скрипт инициализации.
|
|
7
10
|
*/
|
|
8
|
-
export function createExternalConfig(serviceName
|
|
11
|
+
export function createExternalConfig({ serviceName, remoteEntryPath, remoteEntriesGlobalKey, containersGlobalKey, }: {
|
|
12
|
+
serviceName: string;
|
|
13
|
+
remoteEntriesGlobalKey: string;
|
|
14
|
+
containersGlobalKey: string;
|
|
15
|
+
remoteEntryPath: string;
|
|
16
|
+
}): string;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Возвращает скрипт инициализации удаленного модуля.
|
|
4
|
-
* @param {
|
|
5
|
-
* @param {string}
|
|
6
|
-
* @param {string}
|
|
4
|
+
* @param {Object} params Параметры.
|
|
5
|
+
* @param {string} params.serviceName Имя сервиса, содержащего удаленные модули.
|
|
6
|
+
* @param {string} params.remoteEntriesGlobalKey Глобальная переменная,
|
|
7
|
+
* в которой хранятся пути к удаленным точкам входа.
|
|
8
|
+
* @param {string} params.containersGlobalKey Глобальная переменная, в которую добавляются удаленные контейнеры.
|
|
9
|
+
* @param {string} params.remoteEntryPath Путь к remoteEntry, если его не надо получать в рантайме.
|
|
7
10
|
* @return {string} Скрипт инициализации.
|
|
8
11
|
*/
|
|
9
|
-
const createExternalConfig = (serviceName, remoteEntriesGlobalKey, containersGlobalKey) => `promise new Promise((resolve, reject) => {
|
|
12
|
+
const createExternalConfig = ({ serviceName, remoteEntryPath, remoteEntriesGlobalKey, containersGlobalKey, }) => `promise new Promise((resolve, reject) => {
|
|
10
13
|
if (window['${remoteEntriesGlobalKey}']) {
|
|
11
14
|
const scriptElement = document.createElement('script');
|
|
12
15
|
scriptElement.onload = () => {
|
|
@@ -17,7 +20,9 @@ const createExternalConfig = (serviceName, remoteEntriesGlobalKey, containersGlo
|
|
|
17
20
|
scriptElement.remove();
|
|
18
21
|
reject(new Error('Failed loading remoteEntry for "${serviceName}".'));
|
|
19
22
|
};
|
|
20
|
-
scriptElement.src =
|
|
23
|
+
scriptElement.src = ${remoteEntryPath
|
|
24
|
+
? `'${remoteEntryPath}'`
|
|
25
|
+
: `window['${remoteEntriesGlobalKey}']['${serviceName}']`};
|
|
21
26
|
scriptElement.async = true;
|
|
22
27
|
document.head.append(scriptElement);
|
|
23
28
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/module-federation/utils/index.js"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/module-federation/utils/index.js"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;AACH,MAAM,oBAAoB,GAAG,CAAC,EAC5B,WAAW,EACX,eAAe,EACf,sBAAsB,EACtB,mBAAmB,GACpB,EAAE,EAAE,CACD;gBACY,sBAAsB;;;;wBAId,mBAAmB,OAAO,WAAW;;;;0DAIH,WAAW;;0BAE3C,eAAe;IACjC,CAAC,CAAC,IAAI,eAAe,GAAG;IACxB,CAAC,CAAC,WAAW,sBAAsB,OAAO,WAAW,IACzD;;;;yCAIqC,sBAAsB;;GAE5D,CAAC;AAEJ,MAAM,CAAC,OAAO,GAAG,EAAE,oBAAoB,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -35,7 +35,14 @@ const HostServiceConfig = {
|
|
|
35
35
|
{
|
|
36
36
|
name: 'host-service-name',
|
|
37
37
|
remotes: {
|
|
38
|
-
|
|
38
|
+
firstRemoteService: 'first-remote-service-name', // Путь к remote entry определяется в рантайме
|
|
39
|
+
secondRemoteService: {
|
|
40
|
+
name: 'second-remote-service-name', // Путь к remote entry определяется в рантайме
|
|
41
|
+
},
|
|
42
|
+
thirdRemoteService: {
|
|
43
|
+
name: 'third-remote-service-name',
|
|
44
|
+
remoteEntryPath: '//path/to/remoteEntry.js', // Путь к remote entry задан явно
|
|
45
|
+
},
|
|
39
46
|
},
|
|
40
47
|
}
|
|
41
48
|
),
|
|
@@ -8,14 +8,28 @@ const LIBRARY_ERROR_TEXT = [
|
|
|
8
8
|
'For override "library" type use ModuleFederationPlugin.',
|
|
9
9
|
].join(' ');
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const REMOTE_ERROR_TEXT = [
|
|
12
|
+
'The value of the remote element must be a string,',
|
|
13
|
+
'or an object with field `name` for dynamic resolution of `remoteEntry`.',
|
|
14
|
+
'Set `remoteEntryPath` field to object for a static path to `remoteEntry`.',
|
|
15
|
+
].join(' ');
|
|
16
|
+
|
|
17
|
+
/** @typedef {string} RemoteName Имя удаленного сервиса (обычно совпадает с именем в git). */
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {Object} RemoteProperty Опции подключения удаленного сервиса.
|
|
21
|
+
* @property {RemoteName} name Имя удаленного сервиса.
|
|
22
|
+
* @property {string} remoteEntryPath Статический путь к remoteEntry удаленного сервиса.
|
|
23
|
+
* @property {string} [version] Версия удаленного сервиса в формате semver.
|
|
24
|
+
*/
|
|
25
|
+
|
|
12
26
|
/** @typedef {import('webpack').ModuleFederationPluginOptions} MFPluginOriginalOptions Опции. */
|
|
13
27
|
|
|
14
28
|
/**
|
|
15
29
|
* @typedef EnhancedModuleFederationPluginOptions Опции.
|
|
16
30
|
* @param {string} name Имя сервиса.
|
|
17
31
|
* @param {string} filename Имя удаленной точки входа.
|
|
18
|
-
* @param {Object<string,
|
|
32
|
+
* @param {Object<string, RemoteName | RemoteProperty>} [remotes] Удаленные сервисы.
|
|
19
33
|
* @param {MFPluginOriginalOptions.exposes} [exposes] Предоставляемые сервисы.
|
|
20
34
|
* @param {MFPluginOriginalOptions.shared} [shared] Общие зависимости.
|
|
21
35
|
* @param {string} [remoteEntriesGlobalKey = '__RemoteEntriesList__'] Ключ свойства в глобальном объекте,
|
|
@@ -37,6 +51,7 @@ class EnhancedModuleFederationPlugin {
|
|
|
37
51
|
const {
|
|
38
52
|
name,
|
|
39
53
|
library,
|
|
54
|
+
remotes,
|
|
40
55
|
remoteEntriesGlobalKey = '__RemoteEntriesList__',
|
|
41
56
|
containersGlobalKey = '__FederationContainers__',
|
|
42
57
|
} = options;
|
|
@@ -45,6 +60,14 @@ class EnhancedModuleFederationPlugin {
|
|
|
45
60
|
throw new WebpackError(LIBRARY_ERROR_TEXT);
|
|
46
61
|
}
|
|
47
62
|
|
|
63
|
+
if (remotes) {
|
|
64
|
+
Object.values(remotes).forEach(value => {
|
|
65
|
+
if (typeof value !== 'string' && !value?.name) {
|
|
66
|
+
throw new WebpackError(REMOTE_ERROR_TEXT);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
48
71
|
this._options = {
|
|
49
72
|
...options,
|
|
50
73
|
remoteEntriesGlobalKey,
|
|
@@ -70,12 +93,16 @@ class EnhancedModuleFederationPlugin {
|
|
|
70
93
|
|
|
71
94
|
const configuredRemotes = {};
|
|
72
95
|
|
|
73
|
-
remotes && Object.
|
|
74
|
-
|
|
75
|
-
|
|
96
|
+
remotes && Object.entries(remotes).forEach(([key, value]) => {
|
|
97
|
+
const serviceName = value?.name || value;
|
|
98
|
+
const remoteEntryPath = value?.remoteEntryPath;
|
|
99
|
+
|
|
100
|
+
configuredRemotes[key] = { external: createExternalConfig({
|
|
101
|
+
serviceName,
|
|
102
|
+
remoteEntryPath,
|
|
76
103
|
remoteEntriesGlobalKey,
|
|
77
|
-
containersGlobalKey
|
|
78
|
-
) };
|
|
104
|
+
containersGlobalKey,
|
|
105
|
+
}) };
|
|
79
106
|
});
|
|
80
107
|
|
|
81
108
|
compiler.hooks.environment.tap('EnhancedModuleFederationPlugin', () => {
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Возвращает скрипт инициализации удаленного модуля.
|
|
3
|
-
* @param {
|
|
4
|
-
* @param {string}
|
|
5
|
-
* @param {string}
|
|
3
|
+
* @param {Object} params Параметры.
|
|
4
|
+
* @param {string} params.serviceName Имя сервиса, содержащего удаленные модули.
|
|
5
|
+
* @param {string} params.remoteEntriesGlobalKey Глобальная переменная,
|
|
6
|
+
* в которой хранятся пути к удаленным точкам входа.
|
|
7
|
+
* @param {string} params.containersGlobalKey Глобальная переменная, в которую добавляются удаленные контейнеры.
|
|
8
|
+
* @param {string} params.remoteEntryPath Путь к remoteEntry, если его не надо получать в рантайме.
|
|
6
9
|
* @return {string} Скрипт инициализации.
|
|
7
10
|
*/
|
|
8
|
-
const createExternalConfig = (
|
|
11
|
+
const createExternalConfig = ({
|
|
9
12
|
serviceName,
|
|
13
|
+
remoteEntryPath,
|
|
10
14
|
remoteEntriesGlobalKey,
|
|
11
|
-
containersGlobalKey
|
|
12
|
-
) =>
|
|
15
|
+
containersGlobalKey,
|
|
16
|
+
}) =>
|
|
13
17
|
`promise new Promise((resolve, reject) => {
|
|
14
18
|
if (window['${remoteEntriesGlobalKey}']) {
|
|
15
19
|
const scriptElement = document.createElement('script');
|
|
@@ -21,7 +25,10 @@ const createExternalConfig = (
|
|
|
21
25
|
scriptElement.remove();
|
|
22
26
|
reject(new Error('Failed loading remoteEntry for "${serviceName}".'));
|
|
23
27
|
};
|
|
24
|
-
scriptElement.src =
|
|
28
|
+
scriptElement.src = ${remoteEntryPath
|
|
29
|
+
? `'${remoteEntryPath}'`
|
|
30
|
+
: `window['${remoteEntriesGlobalKey}']['${serviceName}']`
|
|
31
|
+
};
|
|
25
32
|
scriptElement.async = true;
|
|
26
33
|
document.head.append(scriptElement);
|
|
27
34
|
} else {
|