@module-federation/modern-js 0.0.0-next-20240515062211
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 +1 -0
- package/dist/CHANGELOG.md +1 -0
- package/dist/LICENSE +21 -0
- package/dist/README.md +1 -0
- package/dist/cjs/cli/index.js +165 -0
- package/dist/cjs/cli/manifest.js +72 -0
- package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +42 -0
- package/dist/cjs/cli/utils.js +62 -0
- package/dist/cjs/constant.js +28 -0
- package/dist/cjs/runtime/MFReactComponent.js +108 -0
- package/dist/cjs/runtime/index.js +31 -0
- package/dist/cjs/types/index.js +16 -0
- package/dist/esm/cli/index.js +157 -0
- package/dist/esm/cli/manifest.js +38 -0
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +24 -0
- package/dist/esm/cli/utils.js +56 -0
- package/dist/esm/constant.js +4 -0
- package/dist/esm/runtime/MFReactComponent.js +77 -0
- package/dist/esm/runtime/index.js +5 -0
- package/dist/esm/types/index.js +0 -0
- package/dist/esm-node/cli/index.js +130 -0
- package/dist/esm-node/cli/manifest.js +38 -0
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +22 -0
- package/dist/esm-node/cli/utils.js +27 -0
- package/dist/esm-node/constant.js +4 -0
- package/dist/esm-node/runtime/MFReactComponent.js +74 -0
- package/dist/esm-node/runtime/index.js +5 -0
- package/dist/esm-node/types/index.js +0 -0
- package/dist/types/cli/index.d.ts +5 -0
- package/dist/types/cli/manifest.d.ts +2 -0
- package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
- package/dist/types/cli/utils.d.ts +4 -0
- package/dist/types/constant.d.ts +1 -0
- package/dist/types/runtime/MFReactComponent.d.ts +7 -0
- package/dist/types/runtime/index.d.ts +2 -0
- package/dist/types/types/index.d.ts +5 -0
- package/package.json +56 -0
- package/types.d.ts +5 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { loadRemote, getInstance } from "@module-federation/enhanced/runtime";
|
|
4
|
+
function getLoadedRemoteInfos(instance, id) {
|
|
5
|
+
const moduleName = instance.remoteHandler.idToModuleNameMap[id];
|
|
6
|
+
if (!moduleName) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const module = instance.moduleCache.get(moduleName);
|
|
10
|
+
if (!module) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const { remoteSnapshot } = instance.snapshotHandler.getGlobalRemoteInfo(module.remoteInfo);
|
|
14
|
+
return {
|
|
15
|
+
...module.remoteInfo,
|
|
16
|
+
snapshot: remoteSnapshot
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function collectLinks(id) {
|
|
20
|
+
const links = [];
|
|
21
|
+
const instance = getInstance();
|
|
22
|
+
if (!instance) {
|
|
23
|
+
return links;
|
|
24
|
+
}
|
|
25
|
+
const loadedRemoteInfo = getLoadedRemoteInfos(instance, id);
|
|
26
|
+
if (!loadedRemoteInfo) {
|
|
27
|
+
return links;
|
|
28
|
+
}
|
|
29
|
+
const snapshot = loadedRemoteInfo.snapshot;
|
|
30
|
+
if (!snapshot) {
|
|
31
|
+
return links;
|
|
32
|
+
}
|
|
33
|
+
const publicPath = "publicPath" in snapshot ? snapshot.publicPath : "getPublicPath" in snapshot ? new Function(snapshot.getPublicPath)() : "";
|
|
34
|
+
if (!publicPath) {
|
|
35
|
+
return links;
|
|
36
|
+
}
|
|
37
|
+
const modules = "modules" in snapshot ? snapshot.modules : [];
|
|
38
|
+
if (modules) {
|
|
39
|
+
modules.forEach((module) => {
|
|
40
|
+
[
|
|
41
|
+
...module.assets.css.sync,
|
|
42
|
+
...module.assets.css.async
|
|
43
|
+
].forEach((file, index) => {
|
|
44
|
+
links.push(/* @__PURE__ */ _jsx("link", {
|
|
45
|
+
href: `${publicPath}${file}`,
|
|
46
|
+
rel: "stylesheet",
|
|
47
|
+
type: "text/css"
|
|
48
|
+
}, index));
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return links;
|
|
53
|
+
}
|
|
54
|
+
function MFReactComponent(props) {
|
|
55
|
+
const { loading = "loading...", id } = props;
|
|
56
|
+
const Component = /* @__PURE__ */ React.lazy(() => loadRemote(id).then((mod) => {
|
|
57
|
+
const links = collectLinks(id);
|
|
58
|
+
return {
|
|
59
|
+
default: () => /* @__PURE__ */ _jsxs("div", {
|
|
60
|
+
children: [
|
|
61
|
+
links,
|
|
62
|
+
/* @__PURE__ */ _jsx(mod.default, {})
|
|
63
|
+
]
|
|
64
|
+
})
|
|
65
|
+
};
|
|
66
|
+
}));
|
|
67
|
+
return /* @__PURE__ */ _jsx(React.Suspense, {
|
|
68
|
+
fallback: loading,
|
|
69
|
+
children: /* @__PURE__ */ _jsx(Component, {})
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
MFReactComponent
|
|
74
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CliPlugin, AppTools } from '@modern-js/app-tools';
|
|
2
|
+
import type { PluginOptions } from '../types';
|
|
3
|
+
export declare const moduleFederationPlugin: (userConfig?: PluginOptions) => CliPlugin<AppTools>;
|
|
4
|
+
export default moduleFederationPlugin;
|
|
5
|
+
export { createModuleFederationConfig } from '@module-federation/enhanced';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
|
+
import { PluginOptions } from '../types';
|
|
3
|
+
export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
|
|
4
|
+
export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MODERN_JS_SERVER_DIR = "bundles";
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@module-federation/modern-js",
|
|
3
|
+
"version": "0.0.0-next-20240515062211",
|
|
4
|
+
"files": [
|
|
5
|
+
"dist/",
|
|
6
|
+
"types.d.ts",
|
|
7
|
+
"README.md"
|
|
8
|
+
],
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/esm/cli/index.js",
|
|
15
|
+
"require": "./dist/cjs/cli/index.js",
|
|
16
|
+
"types": "./dist/types/cli/index.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"./runtime": {
|
|
19
|
+
"types": "./dist/types/runtime/index.d.ts",
|
|
20
|
+
"default": "./dist/esm/runtime/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"typesVersions": {
|
|
24
|
+
"*": {
|
|
25
|
+
".": [
|
|
26
|
+
"./dist/types/cli/index.d.ts"
|
|
27
|
+
],
|
|
28
|
+
"runtime": [
|
|
29
|
+
"./dist/types/runtime/index.d.ts"
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"main": "./dist/cjs/cli/index.js",
|
|
34
|
+
"types": "./dist/types/cli/index.d.ts",
|
|
35
|
+
"author": "hanric <hanric.zhang@gmail.com>",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@swc/helpers": "0.5.3",
|
|
39
|
+
"@modern-js/utils": "^2.49.2",
|
|
40
|
+
"@modern-js/node-bundle-require": "^2.49.2",
|
|
41
|
+
"@module-federation/sdk": "0.0.0-next-20240515062211",
|
|
42
|
+
"@module-federation/enhanced": "0.0.0-next-20240515062211",
|
|
43
|
+
"@module-federation/node": "0.0.0-next-20240515062211"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@modern-js/app-tools": "^2.49.2",
|
|
47
|
+
"@modern-js/core": "^2.49.2",
|
|
48
|
+
"@modern-js/runtime": "^2.49.2",
|
|
49
|
+
"@modern-js/module-tools": "^2.35.0",
|
|
50
|
+
"@modern-js/tsconfig": "^2.35.0",
|
|
51
|
+
"@module-federation/manifest": "0.0.0-next-20240515062211"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "modern build"
|
|
55
|
+
}
|
|
56
|
+
}
|