Skip to content

Commit 638d4e9

Browse files
committed
initial
1 parent fc727a4 commit 638d4e9

Some content is hidden

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

46 files changed

+2434
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
.DS_Store
3+
dist
4+
dist-ssr
5+
*.local
6+
.idea

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "micro-app-demo",
3+
"version": "1.0.0",
4+
"description": "微应用示例",
5+
"main": "index.js",
6+
"scripts": {
7+
"dev": "pnpm -C ./packages/demo-react dev",
8+
"dev1": "pnpm -C ./packages/demo-child-react dev",
9+
"dev2": "pnpm -C ./packages/demo-child-vue dev"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/MinJieLiu/micro-app-demo.git"
14+
},
15+
"keywords": [
16+
"micro-app",
17+
"micro-app-demo"
18+
],
19+
"author": "MinJieLiu",
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/MinJieLiu/micro-app-demo/issues"
23+
},
24+
"homepage": "https://github.com/MinJieLiu/micro-app-demo#readme",
25+
"devDependencies": {
26+
"prettier": "^2.5.1",
27+
"typescript": "^4.5.4"
28+
}
29+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite App</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.tsx"></script>
12+
</body>
13+
</html>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "vite-demo-1",
3+
"version": "0.0.0",
4+
"scripts": {
5+
"dev": "vite",
6+
"build": "tsc && vite build",
7+
"preview": "vite preview"
8+
},
9+
"dependencies": {
10+
"history": "^5.2.0",
11+
"react": "^17.0.2",
12+
"react-dom": "^17.0.2",
13+
"react-router-dom": "^6.2.1"
14+
},
15+
"devDependencies": {
16+
"@types/react": "^17.0.33",
17+
"@types/react-dom": "^17.0.10",
18+
"@vitejs/plugin-react": "^1.0.7",
19+
"less": "^4.1.2",
20+
"vite": "^2.7.2"
21+
}
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.app {
2+
display: flex;
3+
flex-direction: column;
4+
align-items: center;
5+
}
6+
7+
.links {
8+
display: flex;
9+
margin-bottom: 20px;
10+
gap: 20px;
11+
12+
a {
13+
color: steelblue;
14+
15+
&:hover {
16+
text-decoration: underline;
17+
}
18+
}
19+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from "react";
2+
import {
3+
unstable_HistoryRouter as HistoryRouter,
4+
Link,
5+
Route,
6+
Routes,
7+
} from "react-router-dom";
8+
import { BrowserHistory, createBrowserHistory } from "history";
9+
import Example from "./pages/example";
10+
import Foo from "./pages/foo";
11+
import styles from "./App.module.less";
12+
13+
export interface AppProps {
14+
history?: BrowserHistory;
15+
}
16+
17+
const currentHistory = createBrowserHistory();
18+
19+
function App({ history = currentHistory }: AppProps) {
20+
React.useEffect(() => {
21+
console.log("[mount] - React child");
22+
return () => {
23+
console.log("[unmount] - React child");
24+
};
25+
}, []);
26+
27+
return (
28+
<div className={styles.app}>
29+
<HistoryRouter basename="/react" history={history}>
30+
<div className={styles.links}>
31+
<Link to="/">子系统首页</Link>
32+
<Link to="/foo">子系统子路由</Link>
33+
</div>
34+
<Routes>
35+
<Route path="/" element={<Example />} />
36+
<Route path="/foo" element={<Foo />} />
37+
</Routes>
38+
</HistoryRouter>
39+
</div>
40+
);
41+
}
42+
43+
export default App;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
body {
2+
margin: 0;
3+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4+
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5+
sans-serif;
6+
-webkit-font-smoothing: antialiased;
7+
-moz-osx-font-smoothing: grayscale;
8+
}
9+
10+
code {
11+
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12+
monospace;
13+
}
Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from "react";
2+
import ReactDOM from "react-dom";
3+
import "./index.css";
4+
import App, { AppProps } from "./App";
5+
6+
// 单独开发环境
7+
if (!import.meta.url.includes("microAppEnv")) {
8+
ReactDOM.render(
9+
<React.StrictMode>
10+
<App />
11+
</React.StrictMode>,
12+
document.getElementById("root")
13+
);
14+
}
15+
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+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Example() {
2+
return <div>当前位置:子应用首页</div>;
3+
}

0 commit comments

Comments
 (0)