Skip to content

Commit abbed6f

Browse files
committed
提供 build 示例
1 parent 84c02c8 commit abbed6f

File tree

9 files changed

+45
-46
lines changed

9 files changed

+45
-46
lines changed

.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"singleQuote": true
3+
}

packages/demo-child-react/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
"preview": "vite preview"
88
},
99
"dependencies": {
10+
"@micro-web/sub": "^0.2.0",
1011
"history": "^5.2.0",
1112
"react": "^17.0.2",
1213
"react-dom": "^17.0.2",
1314
"react-router-dom": "^6.2.1"
1415
},
1516
"devDependencies": {
17+
"@micro-web/vite-plugin": "^0.2.0",
1618
"@types/react": "^17.0.33",
1719
"@types/react-dom": "^17.0.10",
1820
"@vitejs/plugin-react": "^1.0.7",
Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,17 @@
1-
import React from "react";
2-
import ReactDOM from "react-dom";
3-
import "./index.css";
4-
import App, { AppProps } from "./App";
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import { withReactMicroApp } from '@micro-web/sub';
4+
import './index.css';
5+
import App from './App';
56

67
// 单独开发环境
7-
if (!import.meta.url.includes("microAppEnv")) {
8+
if (!import.meta.url.includes('microAppEnv')) {
89
ReactDOM.render(
910
<React.StrictMode>
1011
<App />
1112
</React.StrictMode>,
12-
document.getElementById("root")
13+
document.getElementById('root')
1314
);
1415
}
1516

16-
export default (container: HTMLElement) => {
17-
let handleRender: (props: AppProps) => void;
18-
19-
function Main(props: AppProps) {
20-
const [state, setState] = React.useState(props);
21-
handleRender = setState;
22-
return <App {...state} />;
23-
}
24-
25-
return {
26-
mount(props: AppProps) {
27-
ReactDOM.render(<Main {...props} />, container);
28-
},
29-
render(props: AppProps) {
30-
handleRender?.(props);
31-
},
32-
unmount() {
33-
ReactDOM.unmountComponentAtNode(container);
34-
},
35-
};
36-
};
17+
export default withReactMicroApp(App);

packages/demo-child-react/src/pages/foo/index.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import logo from "../../logo.svg";
2-
import styles from "./Foo.module.css";
3-
4-
const logoURL = new URL(logo, import.meta.url);
1+
import logo from '../../logo.svg';
2+
import styles from './Foo.module.css';
53

64
export default function Foo() {
75
return (
86
<>
9-
<img className={styles.img} alt="" src={logoURL.href} />
7+
<img className={styles.img} alt="" src={logo} />
108
<div className={styles.foo}>当前位置:子应用子路由</div>
119
</>
1210
);

packages/demo-child-react/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"useDefineForClassFields": true,
55
"lib": ["DOM", "DOM.Iterable", "ESNext"],
66
"allowJs": false,
7-
"skipLibCheck": false,
7+
"skipLibCheck": true,
88
"esModuleInterop": false,
99
"allowSyntheticDefaultImports": true,
1010
"strict": true,
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { defineConfig } from "vite";
2-
import react from "@vitejs/plugin-react";
1+
import { defineConfig } from 'vite';
2+
import react from '@vitejs/plugin-react';
3+
import { microWebPlugin } from '@micro-web/vite-plugin';
34

45
// https://vitejs.dev/config/
56
export default defineConfig({
6-
base: "/react/",
7+
base: '/react/',
78
server: {
89
port: 3002,
910
},
10-
plugins: [react()],
11+
plugins: [react(), microWebPlugin()],
1112
});

packages/demo-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"preview": "vite preview"
88
},
99
"dependencies": {
10-
"@micro-web/app": "^0.1.3",
10+
"@micro-web/app": "^0.2.0",
1111
"@types/systemjs": "^6.1.1",
1212
"history": "^5.2.0",
1313
"react": "^17.0.2",

packages/demo-react/src/pages/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Routes, Route } from "react-router-dom";
2-
import { MicroApp } from "@micro-web/app";
3-
import { history } from "../common/history";
4-
import { Example } from "./example";
1+
import { Routes, Route } from 'react-router-dom';
2+
import { MicroApp } from '@micro-web/app';
3+
import { history } from '../common/history';
4+
import { Example } from './example';
55

66
export default function Pages() {
77
return (
@@ -11,6 +11,7 @@ export default function Pages() {
1111
path="/react/*"
1212
element={
1313
<MicroApp
14+
key="react"
1415
className="micro-app"
1516
entry="//localhost:3002/react/src/main.tsx"
1617
fallback="加载中"
@@ -22,6 +23,7 @@ export default function Pages() {
2223
path="/vue/*"
2324
element={
2425
<MicroApp
26+
key="vue"
2527
className="micro-app"
2628
entry="//localhost:3004/vue/src/main.ts"
2729
fallback="加载中"

pnpm-lock.yaml

Lines changed: 16 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)