Skip to content

Commit ca7387c

Browse files
committed
feat: add data loader demo
1 parent 5994b0c commit ca7387c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+58762
-44648
lines changed

modernjs-ssr-data-loader/.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry=https://registry.yarnpkg.com

modernjs-ssr-data-loader/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# advance-ssr-demo
2+
3+
This demo shows ssr with data loader in provider and ssr by route abilities.
4+
5+
## how to start?
6+
7+
Run `yarn` to install the dependencies.
8+
9+
Run `pnpm run start`. This will build and serve both `host` and `remote` on ports 3062 and 3061 respectively.
10+
11+
12+
Visit follow url in browser:
13+
* [SSR with data loader in provider](http://localhost:3062/entry-one/nested-routes/pathname)
14+
* [CSR](http://localhost:3062/entry-two)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './compiled-types/src/components/Content';
2+
export { default } from './compiled-types/src/components/Content';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
export type RemoteKeys = 'host/Content' | 'host/mf-full-routes' | 'host/mf-slim-routes' | 'host/mf-routes-meta' | 'host/mf-routes';
3+
type PackageType<T> = T extends 'host/mf-routes' ? typeof import('host/mf-routes') :T extends 'host/mf-routes-meta' ? typeof import('host/mf-routes-meta') :T extends 'host/mf-slim-routes' ? typeof import('host/mf-slim-routes') :T extends 'host/mf-full-routes' ? typeof import('host/mf-full-routes') :T extends 'host/Content' ? typeof import('host/Content') :any;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare const _default: () => JSX.Element;
2+
export default _default;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './compiled-types/node_modules/.federation/mf-full-routes';
2+
export { default } from './compiled-types/node_modules/.federation/mf-full-routes';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './compiled-types/node_modules/.federation/mf-routes-meta';
2+
export { default } from './compiled-types/node_modules/.federation/mf-routes-meta';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './compiled-types/node_modules/.federation/mf-routes';
2+
export { default } from './compiled-types/node_modules/.federation/mf-routes';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './compiled-types/node_modules/.federation/mf-slim-routes';
2+
export { default } from './compiled-types/node_modules/.federation/mf-slim-routes';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import type { PackageType as PackageType_0,RemoteKeys as RemoteKeys_0 } from './host/apis.d.ts';
2+
import type { PackageType as PackageType_1,RemoteKeys as RemoteKeys_1 } from './remote/apis.d.ts';
3+
declare module "@module-federation/runtime" {
4+
type RemoteKeys = RemoteKeys_0 | RemoteKeys_1;
5+
type PackageType<T, Y=any> = T extends RemoteKeys_0 ? PackageType_0<T> :
6+
T extends RemoteKeys_1 ? PackageType_1<T> :
7+
Y ;
8+
export function loadRemote<T extends RemoteKeys,Y>(packageName: T): Promise<PackageType<T, Y>>;
9+
export function loadRemote<T extends string,Y>(packageName: T): Promise<PackageType<T, Y>>;
10+
}
11+
declare module "@module-federation/enhanced/runtime" {
12+
type RemoteKeys = RemoteKeys_0 | RemoteKeys_1;
13+
type PackageType<T, Y=any> = T extends RemoteKeys_0 ? PackageType_0<T> :
14+
T extends RemoteKeys_1 ? PackageType_1<T> :
15+
Y ;
16+
export function loadRemote<T extends RemoteKeys,Y>(packageName: T): Promise<PackageType<T, Y>>;
17+
export function loadRemote<T extends string,Y>(packageName: T): Promise<PackageType<T, Y>>;
18+
}
19+
declare module "@module-federation/runtime-tools" {
20+
type RemoteKeys = RemoteKeys_0 | RemoteKeys_1;
21+
type PackageType<T, Y=any> = T extends RemoteKeys_0 ? PackageType_0<T> :
22+
T extends RemoteKeys_1 ? PackageType_1<T> :
23+
Y ;
24+
export function loadRemote<T extends RemoteKeys,Y>(packageName: T): Promise<PackageType<T, Y>>;
25+
export function loadRemote<T extends string,Y>(packageName: T): Promise<PackageType<T, Y>>;
26+
}
27+
declare module "@modern-js/runtime/mf" {
28+
type RemoteKeys = RemoteKeys_0 | RemoteKeys_1;
29+
type PackageType<T, Y=any> = T extends RemoteKeys_0 ? PackageType_0<T> :
30+
T extends RemoteKeys_1 ? PackageType_1<T> :
31+
Y ;
32+
export function loadRemote<T extends RemoteKeys,Y>(packageName: T): Promise<PackageType<T, Y>>;
33+
export function loadRemote<T extends string,Y>(packageName: T): Promise<PackageType<T, Y>>;
34+
}
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './compiled-types/src/components/Button';
2+
export { default } from './compiled-types/src/components/Button';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './compiled-types/src/components/Image';
2+
export { default } from './compiled-types/src/components/Image';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
export type RemoteKeys = 'remote/Image' | 'remote/Button' | 'remote/main/mf-routes' | 'remote/main/route-server-loaders';
3+
type PackageType<T> = T extends 'remote/main/route-server-loaders' ? typeof import('remote/main/route-server-loaders') :T extends 'remote/main/mf-routes' ? typeof import('remote/main/mf-routes') :T extends 'remote/Button' ? typeof import('remote/Button') :T extends 'remote/Image' ? typeof import('remote/Image') :any;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import React from 'react';
2+
export declare const Button: () => React.JSX.Element;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// <reference types="react" />
2+
declare const _default: () => JSX.Element;
3+
export default _default;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './../compiled-types/node_modules/.federation/data-loader/main/mf-routes';
2+
export { default } from './../compiled-types/node_modules/.federation/data-loader/main/mf-routes';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './../compiled-types/node_modules/.federation/data-loader/main/route-server-loaders-client';
2+
export { default } from './../compiled-types/node_modules/.federation/data-loader/main/route-server-loaders-client';
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# modernjs-ssr-nested-remote
2+
3+
## 0.1.13
4+
5+
### Patch Changes
6+
7+
- @module-federation/modern-js@0.3.3
8+
9+
## 0.1.12
10+
11+
### Patch Changes
12+
13+
- Updated dependencies [85ae159]
14+
- @module-federation/modern-js@0.3.2
15+
16+
## 0.1.13
17+
18+
### Patch Changes
19+
20+
- @module-federation/modern-js@0.3.1
21+
22+
## 0.1.12
23+
24+
### Patch Changes
25+
26+
- Updated dependencies [fa37cc4]
27+
- @module-federation/modern-js@0.2.0
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
3+
"vcs": {
4+
"enabled": true,
5+
"defaultBranch": "main",
6+
"clientKind": "git",
7+
"useIgnoreFile": true
8+
},
9+
"formatter": {
10+
"enabled": true,
11+
"indentStyle": "space"
12+
},
13+
"javascript": {
14+
"formatter": {
15+
"quoteStyle": "single",
16+
"arrowParentheses": "asNeeded",
17+
"jsxQuoteStyle": "double",
18+
"lineWidth": 80
19+
}
20+
},
21+
"linter": {
22+
"enabled": true,
23+
"rules": {
24+
"recommended": true
25+
}
26+
},
27+
"organizeImports": {
28+
"enabled": true
29+
},
30+
"files": {
31+
"ignoreUnknown": true,
32+
"ignore": [".vscode/**/*", "node_modules/**/*", "dist/**/*"]
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { appTools, defineConfig } from '@modern-js/app-tools';
2+
import { moduleFederationPlugin } from '@module-federation/modern-js';
3+
4+
// https://modernjs.dev/en/configure/app/usage
5+
export default defineConfig({
6+
runtime: {
7+
router: true,
8+
},
9+
server: {
10+
ssr: {
11+
mode: 'stream',
12+
},
13+
ssrByRouteIds: ['entry-one_nested-routes/pathname/layout'],
14+
port: 3062,
15+
},
16+
plugins: [
17+
appTools({
18+
bundler: 'webpack',
19+
}),
20+
moduleFederationPlugin({
21+
dataLoader: true,
22+
}),
23+
],
24+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { createModuleFederationConfig } from '@module-federation/modern-js';
2+
export default createModuleFederationConfig({
3+
name: 'host',
4+
filename: 'remoteEntry.js',
5+
// exposes: {
6+
// './Content': './src/entry-one/components/Content.tsx',
7+
// },
8+
remotes: {
9+
remote: 'remote@http://localhost:3061/mf-manifest.json',
10+
},
11+
shared: {
12+
react: { singleton: true },
13+
'react-dom': { singleton: true },
14+
},
15+
});
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "modernjs-ssr-data-loader-host",
3+
"private": true,
4+
"version": "0.1.13",
5+
"scripts": {
6+
"reset": "npx rimraf ./**/node_modules",
7+
"dev": "modern dev",
8+
"build": "modern build",
9+
"start": "modern start",
10+
"serve": "modern serve",
11+
"new": "modern new",
12+
"lint": "biome check",
13+
"prepare": "simple-git-hooks",
14+
"upgrade": "modern upgrade"
15+
},
16+
"engines": {
17+
"node": ">=16.18.1"
18+
},
19+
"lint-staged": {
20+
"*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}": [
21+
"biome check --files-ignore-unknown=true"
22+
]
23+
},
24+
"simple-git-hooks": {
25+
"pre-commit": "npx lint-staged"
26+
},
27+
"dependencies": {
28+
"@modern-js/runtime": "2.60.2",
29+
"react": "~18.2.0",
30+
"react-dom": "~18.2.0",
31+
"@module-federation/modern-js": "0.0.0-next-20241014092946",
32+
"@babel/runtime": "7.24.4",
33+
"antd": "4.24.15"
34+
},
35+
"devDependencies": {
36+
"@modern-js/app-tools": "2.60.2",
37+
"@modern-js/tsconfig": "2.60.2",
38+
"typescript": "~5.0.4",
39+
"@types/jest": "~29.5.0",
40+
"@types/node": "~16.11.7",
41+
"@types/react": "~18.2.0",
42+
"@types/react-dom": "~18.2.0",
43+
"lint-staged": "~13.1.0",
44+
"prettier": "~2.8.1",
45+
"rimraf": "~3.0.2",
46+
"simple-git-hooks": "^2.11.1",
47+
"@biomejs/biome": "1.8.3"
48+
}
49+
}

0 commit comments

Comments
 (0)