-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
liangxiaoming
committed
Oct 27, 2024
1 parent
8fe29ee
commit 69b3e9d
Showing
17 changed files
with
281 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# EMP3 React18 DEMO with base config | ||
|
||
## 运行 | ||
``` | ||
pnpm i | ||
pnpm dev | ||
``` | ||
|
||
[文档说明](https://empjs.dev/guide/empShare/react.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "emp3-react18-demo", | ||
"ignored": true, | ||
"version": "0.0.1", | ||
"scripts": { | ||
"dev": "pnpm --filter runtime-18-* --parallel dev", | ||
"build": "pnpm --filter runtime-18-* --parallel build", | ||
"serve": "pnpm --filter runtime-18-* --parallel serve", | ||
"stat": "pnpm --filter runtime-18-* --parallel stat" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {defineConfig} from '@empjs/cli' | ||
import pluginReact from '@empjs/plugin-react' | ||
import {pluginRspackEmpShare} from '@empjs/share' | ||
export default defineConfig(store => { | ||
return { | ||
plugins: [ | ||
pluginReact(), | ||
pluginRspackEmpShare({ | ||
empRuntime: { | ||
runtimeLib: "https://unpkg.com/@empjs/[email protected]/output/sdk.js", | ||
frameworkLib: "https://unpkg.com/@empjs/[email protected]/dist", | ||
frameworkGlobal: 'EMP_ADAPTER_REACT', | ||
framework: 'react', | ||
}, | ||
}), | ||
], | ||
build: { | ||
polyfill: { | ||
entryCdn: "https://unpkg.com/@empjs/[email protected]/dist/es.js", | ||
}, | ||
}, | ||
server: { | ||
port: 1801, | ||
open: false, | ||
}, | ||
html: { | ||
template: 'src/index.html', | ||
}, | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "runtime-18-app", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"scripts": { | ||
"dev": "emp dev", | ||
"build": "emp build", | ||
"start": "emp serve", | ||
"stat": "emp build --analyze", | ||
"emp": "emp" | ||
}, | ||
"dependencies": { | ||
"@empjs/share": "3.2.0", | ||
"react": "18", | ||
"react-dom": "18" | ||
}, | ||
"devDependencies": { | ||
"@empjs/cli": "3.2.7", | ||
"@empjs/plugin-react": "3.2.0", | ||
"@types/react": "18", | ||
"@types/react-dom": "18" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {reactAdapter} from '@empjs/share/adapter' | ||
import rt from '@empjs/share/runtime' | ||
import {Suspense, lazy} from 'react' | ||
// 实例化 | ||
rt.init({ | ||
name: 'runtimeHost', | ||
shared: reactAdapter.shared, | ||
remotes: [ | ||
// { | ||
// name: 'runtime_18_host', | ||
// entry: 'http://localhost:1802/emp.js', | ||
// }, | ||
], | ||
}) | ||
// 动态注册 | ||
rt.register([ | ||
{ | ||
name: 'runtimeHost', | ||
entry: 'http://localhost:1802/output/emp.js', | ||
// entry: 'https://emp-demo-react18-host.pages.dev/demos/react18/react-host/dist/mf-manifest.json' | ||
}, | ||
]) | ||
const RemoteApp = lazy(() => rt.load('runtimeHost/App')) | ||
console.log('RemoteApp', RemoteApp) | ||
const App = () => ( | ||
<div> | ||
<h1>React 18 Runtime App</h1> | ||
<Suspense><RemoteApp name="from home" /></Suspense> | ||
</div> | ||
) | ||
export default App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {createRoot} from 'react-dom/client' | ||
import App from './App' | ||
const dom = document.getElementById('emp-root')! | ||
const root = createRoot(dom) | ||
root.render(<App />) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="zh-CN"> | ||
|
||
<head> | ||
<title>runtime_18_app</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
</head> | ||
|
||
<body> | ||
<script src="https://yo-debug.yy.com/target.js"></script> | ||
<div id="emp-root"></div> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import('./bootstrap') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "@empjs/cli/emp-tsconfig.json", | ||
"compilerOptions": { | ||
"baseUrl": "./", | ||
"paths": { | ||
"*": ["./@mf-types/*"] | ||
} | ||
}, | ||
"include": ["src"] | ||
} |
34 changes: 34 additions & 0 deletions
34
demos/react18_with_base_config/react-host-with-base-config/emp.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {defineConfig} from '@empjs/cli' | ||
import pluginReact from '@empjs/plugin-react' | ||
import {pluginRspackEmpShare} from '@empjs/share' | ||
export default defineConfig(store => { | ||
return { | ||
plugins: [ | ||
pluginReact(), | ||
pluginRspackEmpShare({ | ||
name: "runtimeHost", | ||
exposes: { | ||
'./App': './src/App', | ||
'./CountComp': './src/CountComp', | ||
}, | ||
empRuntime: { | ||
runtimeLib: "https://unpkg.com/@empjs/[email protected]/output/sdk.js", | ||
frameworkLib: "https://unpkg.com/@empjs/[email protected]/dist", | ||
frameworkGlobal: 'EMP_ADAPTER_REACT', | ||
framework: 'react', | ||
}, | ||
manifest: true | ||
}), | ||
], | ||
base: '/output/', | ||
build: { | ||
polyfill: { | ||
entryCdn: "https://unpkg.com/@empjs/[email protected]/dist/es.js", | ||
}, | ||
}, | ||
server: { | ||
port: 1802, | ||
open: false, | ||
}, | ||
} | ||
}) |
26 changes: 26 additions & 0 deletions
26
demos/react18_with_base_config/react-host-with-base-config/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "runtime-18-host", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"scripts": { | ||
"dev": "emp dev", | ||
"build": "emp build", | ||
"start": "emp serve", | ||
"stat": "emp build --analyze" | ||
}, | ||
"dependencies": { | ||
"@empjs/share": "3.2.0", | ||
"react": "18", | ||
"react-dom": "18" | ||
}, | ||
"devDependencies": { | ||
"@empjs/cli": "3.2.7", | ||
"@empjs/plugin-react": "3.2.0", | ||
"@types/react": "18", | ||
"@types/react-dom": "18" | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
demos/react18_with_base_config/react-host-with-base-config/src/App.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {CountComp} from './CountComp' | ||
type HostType = { | ||
name?: string | ||
children?: React.ReactNode | ||
} | ||
const App = ({name, children}: HostType) => { | ||
return ( | ||
<div> | ||
<h1>React 18 Runtime Host: {name ? name : ''}</h1> | ||
<CountComp /> | ||
{children} | ||
</div> | ||
) | ||
} | ||
export default App |
11 changes: 11 additions & 0 deletions
11
demos/react18_with_base_config/react-host-with-base-config/src/CountComp.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { version } from 'react' | ||
|
||
export const CountComp = () => { | ||
return ( | ||
<div> | ||
<h3> | ||
CountCompWrap React Version: {version} | ||
</h3> | ||
</div> | ||
) | ||
} |
5 changes: 5 additions & 0 deletions
5
demos/react18_with_base_config/react-host-with-base-config/src/bootstrap.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {createRoot} from 'react-dom/client' | ||
import App from './App' | ||
const dom = document.getElementById('emp-root')! | ||
const root = createRoot(dom) | ||
root.render(<App />) |
1 change: 1 addition & 0 deletions
1
demos/react18_with_base_config/react-host-with-base-config/src/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import('./bootstrap') |
10 changes: 10 additions & 0 deletions
10
demos/react18_with_base_config/react-host-with-base-config/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "@empjs/cli/emp-tsconfig.json", | ||
"compilerOptions": { | ||
"baseUrl": "./", | ||
"paths": { | ||
"*": ["./@mf-types/*"] | ||
} | ||
}, | ||
"include": ["src"] | ||
} |
Oops, something went wrong.