Skip to content

Commit 0bddae0

Browse files
authored
feat: add modernjs ssr demo (#4174)
* feat: add modernjs ssr demo * chore: upgrade modernjs dep * chore: use rspack ssr * chore: use rspack host * chore: remove useless code
1 parent 0fea90f commit 0bddae0

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

+14951
-9723
lines changed

modernjs-ssr/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry=https://registry.yarnpkg.com

modernjs-ssr/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Module Federation example for Modern.js Framework
2+
3+
- HOST: [localhost:3007](http://localhost:3007/)
4+
- REMOTE: [localhost:3006](http://localhost:3006/)
5+
6+
# Running Demo
7+
8+
Run `yarn` to install the dependencies.
9+
10+
Run `pnpm run start`. This will build and serve both `host` and `provider` on ports 3007 and 3006 respectively.
11+
12+
- [localhost:3007](http://localhost:3007/) (HOST)
13+
- [localhost:3006](http://localhost:3006/) (STANDALONE REMOTE)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['@modern-js'],
4+
};

modernjs-ssr/dynamic-provider/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
strict-peer-dependencies=false

modernjs-ssr/dynamic-provider/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lts/gallium
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Your App
2+
3+
## Setup
4+
5+
Install the dependencies:
6+
7+
```bash
8+
yarn install
9+
```
10+
11+
## Get Started
12+
13+
Start the dev server:
14+
15+
```
16+
yarn dev
17+
```
18+
19+
Enable optional features or add a new entry:
20+
21+
```
22+
yarn new
23+
```
24+
25+
Build the app for production:
26+
27+
```
28+
yarn build
29+
```
30+
31+
Preview the production build locally:
32+
33+
```
34+
yarn serve
35+
```
36+
37+
For more information, see the [Modern.js documentation](​https://modernjs.dev/en).
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
dev:{
7+
// FIXME: it should be removed , related issue: https://github.com/web-infra-dev/modern.js/issues/5999
8+
host: '0.0.0.0',
9+
},
10+
runtime: {
11+
router: true,
12+
},
13+
server: {
14+
ssr: {
15+
mode: 'stream',
16+
},
17+
port: 3008,
18+
},
19+
plugins: [
20+
appTools({bundler:'experimental-rspack'}),
21+
moduleFederationPlugin()
22+
],
23+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { createModuleFederationConfig } from '@module-federation/modern-js';
2+
3+
export default createModuleFederationConfig({
4+
name: 'dynamic_provider',
5+
filename: 'remoteEntry.js',
6+
exposes: {
7+
'./Image': './src/components/Image.tsx',
8+
},
9+
shared: {
10+
react: { singleton: true },
11+
'react-dom': { singleton: true },
12+
},
13+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "modernjs-ssr-dynamic-provider",
3+
"version": "0.1.0",
4+
"scripts": {
5+
"reset": "npx rimraf ./**/node_modules",
6+
"dev": "modern dev",
7+
"build": "modern build",
8+
"start": "modern start",
9+
"serve": "modern serve",
10+
"new": "modern new",
11+
"lint": "modern lint",
12+
"upgrade": "modern upgrade"
13+
},
14+
"engines": {
15+
"node": ">=16.18.1"
16+
},
17+
"lint-staged": {
18+
"*.{ts,tsx}": [
19+
"node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"
20+
],
21+
"*.{js,jsx,mjs,mjsx,cjs,cjsx}": [
22+
"node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"
23+
]
24+
},
25+
"eslintIgnore": [
26+
"node_modules/",
27+
"dist/"
28+
],
29+
"dependencies": {
30+
"@modern-js/runtime": "2.56.2",
31+
"react": "~18.3.0",
32+
"react-dom": "~18.3.0",
33+
"@module-federation/modern-js":"0.0.0-next-20240725061440"
34+
},
35+
"devDependencies": {
36+
"@modern-js/app-tools": "2.56.2",
37+
"@modern-js/eslint-config": "2.56.2",
38+
"@modern-js/tsconfig": "2.56.2",
39+
"@modern-js-app/eslint-config": "2.56.2",
40+
"lint-staged": "15.2.7",
41+
"prettier": "3.3.2",
42+
"husky": "9.0.11",
43+
"rimraf": "5.0.7",
44+
"typescript": "4.9.5",
45+
"@types/jest": "29.5.12",
46+
"@types/node": "16.18.101",
47+
"@types/react": "18.3.3",
48+
"@types/react-dom": "18.3.0"
49+
}
50+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// eslint-disable-next-line import/no-commonjs
2+
module.exports = {
3+
root: true,
4+
extends: ['@modern-js-app'],
5+
parserOptions: {
6+
tsconfigRootDir: __dirname,
7+
project: ['../tsconfig.json'],
8+
},
9+
};

0 commit comments

Comments
 (0)