@lvetechs/micro-app 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -4
- package/dist/index.d.ts +6 -0
- package/package.json +24 -3
- /package/dist/{index.umd.js → index.js} +0 -0
- /package/dist/{index.es.js → index.mjs} +0 -0
package/README.md
CHANGED
|
@@ -16,16 +16,17 @@ npm install @lvetechs/micro-app
|
|
|
16
16
|
{
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"react": ">=16.8.0",
|
|
19
|
-
"react-dom": ">=16.8.0"
|
|
19
|
+
"react-dom": ">=16.8.0",
|
|
20
|
+
"vue": ">=3.0.0"
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
```
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
> **注意**:Vue 是可选依赖。如果在 Vue 项目中使用,需要安装 Vue;如果在 React 项目中使用,需要安装 React。
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
## 在 React 项目中使用
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
### 方式一:函数式实例化
|
|
29
30
|
|
|
30
31
|
```tsx
|
|
31
32
|
import { createMicroApp } from '@lvetechs/micro-app'
|
|
@@ -228,6 +229,84 @@ function App() {
|
|
|
228
229
|
<!-- 组件式会自动创建,但容器选择器需要匹配配置 -->
|
|
229
230
|
```
|
|
230
231
|
|
|
232
|
+
## 在 Vue 项目中使用
|
|
233
|
+
|
|
234
|
+
### 方式一:函数式实例化
|
|
235
|
+
|
|
236
|
+
与 React 项目相同,使用 `createMicroApp` 函数:
|
|
237
|
+
|
|
238
|
+
```vue
|
|
239
|
+
<script setup lang="ts">
|
|
240
|
+
import { createMicroApp } from '@lvetechs/micro-app'
|
|
241
|
+
|
|
242
|
+
const microApp = createMicroApp({
|
|
243
|
+
apps: [
|
|
244
|
+
{
|
|
245
|
+
name: 'react-app',
|
|
246
|
+
entry: 'http://localhost:3001',
|
|
247
|
+
container: '#react-app-container',
|
|
248
|
+
mode: 'iframe',
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
onStatusChange: (name, status) => {
|
|
252
|
+
console.log(`[${name}] 状态变化: ${status}`)
|
|
253
|
+
},
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
// 启动应用
|
|
257
|
+
microApp.startApp('react-app')
|
|
258
|
+
</script>
|
|
259
|
+
|
|
260
|
+
<template>
|
|
261
|
+
<div id="react-app-container"></div>
|
|
262
|
+
</template>
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### 方式二:使用 Vue 组件
|
|
266
|
+
|
|
267
|
+
在 Vue 3 项目中可以使用 `MicroAppVue.vue` 组件:
|
|
268
|
+
|
|
269
|
+
```vue
|
|
270
|
+
<script setup lang="ts">
|
|
271
|
+
import { ref } from 'vue'
|
|
272
|
+
import MicroAppVue from '@lvetechs/micro-app/dist/components/MicroAppVue.vue'
|
|
273
|
+
|
|
274
|
+
const apps = [
|
|
275
|
+
{
|
|
276
|
+
name: 'react-app',
|
|
277
|
+
entry: 'http://localhost:3001',
|
|
278
|
+
container: '#vue-app-container',
|
|
279
|
+
active_rule: '/app/react',
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
name: 'vue-app',
|
|
283
|
+
entry: 'http://localhost:3002',
|
|
284
|
+
container: '#vue-app-container',
|
|
285
|
+
active_rule: '/app/vue',
|
|
286
|
+
},
|
|
287
|
+
]
|
|
288
|
+
|
|
289
|
+
const activeApp = ref(apps[0].name)
|
|
290
|
+
</script>
|
|
291
|
+
|
|
292
|
+
<template>
|
|
293
|
+
<div>
|
|
294
|
+
<!-- 切换按钮 -->
|
|
295
|
+
<button @click="activeApp = 'react-app'">React App</button>
|
|
296
|
+
<button @click="activeApp = 'vue-app'">Vue App</button>
|
|
297
|
+
|
|
298
|
+
<!-- 微应用组件 -->
|
|
299
|
+
<MicroAppVue
|
|
300
|
+
:apps="apps"
|
|
301
|
+
:active-app="activeApp"
|
|
302
|
+
@status-change="(name, status) => console.log(name, status)"
|
|
303
|
+
/>
|
|
304
|
+
</div>
|
|
305
|
+
</template>
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
> **注意**:使用 Vue 组件时,需要在项目中安装 `@vitejs/plugin-vue`。
|
|
309
|
+
|
|
231
310
|
## 打包
|
|
232
311
|
|
|
233
312
|
```bash
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
*
|
|
6
6
|
* 轻量级微前端框架
|
|
7
7
|
* 支持函数式实例化和组件式实例化两种模式
|
|
8
|
+
* 同时支持 React 和 Vue
|
|
9
|
+
*
|
|
10
|
+
* 使用方式:
|
|
11
|
+
* - React: import { MicroApp, createMicroApp } from '@lvetechs/micro-app'
|
|
12
|
+
* - Vue: import { createMicroApp } from '@lvetechs/micro-app'
|
|
13
|
+
* 并使用 src/components/MicroAppVue.vue 组件
|
|
8
14
|
*/
|
|
9
15
|
export type { MicroAppStatus, LoadMode, SubAppConfig, MicroAppInfo, MicroAppInstance, MicroAppOptions, MicroAppService, } from './types';
|
|
10
16
|
export { createMicroApp } from './core/MicroAppManager';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvetechs/micro-app",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "轻量级微前端框架 - 支持函数式和组件式实例化",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,10 +12,29 @@
|
|
|
12
12
|
"LICENSE",
|
|
13
13
|
"README.md"
|
|
14
14
|
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.mjs",
|
|
19
|
+
"require": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
15
22
|
"peerDependencies": {
|
|
16
23
|
"react": "^18.2.0",
|
|
17
24
|
"react-dom": "^18.2.0",
|
|
18
|
-
"react-router-dom": "^6.30.3"
|
|
25
|
+
"react-router-dom": "^6.30.3",
|
|
26
|
+
"vue": "^3.4.0"
|
|
27
|
+
},
|
|
28
|
+
"peerDependenciesMeta": {
|
|
29
|
+
"react": {
|
|
30
|
+
"optional": true
|
|
31
|
+
},
|
|
32
|
+
"react-dom": {
|
|
33
|
+
"optional": true
|
|
34
|
+
},
|
|
35
|
+
"vue": {
|
|
36
|
+
"optional": true
|
|
37
|
+
}
|
|
19
38
|
},
|
|
20
39
|
"devDependencies": {
|
|
21
40
|
"@types/react": "^18.2.66",
|
|
@@ -23,6 +42,7 @@
|
|
|
23
42
|
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
|
24
43
|
"@typescript-eslint/parser": "^7.2.0",
|
|
25
44
|
"@vitejs/plugin-react": "^4.2.1",
|
|
45
|
+
"@vitejs/plugin-vue": "^5.0.0",
|
|
26
46
|
"autoprefixer": "^10.4.19",
|
|
27
47
|
"eslint": "^8.57.0",
|
|
28
48
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
@@ -31,7 +51,8 @@
|
|
|
31
51
|
"tailwindcss": "^3.4.3",
|
|
32
52
|
"typescript": "^5.2.2",
|
|
33
53
|
"vite": "^5.2.0",
|
|
34
|
-
"vite-plugin-dts": "^3.9.1"
|
|
54
|
+
"vite-plugin-dts": "^3.9.1",
|
|
55
|
+
"vue": "^3.4.0"
|
|
35
56
|
},
|
|
36
57
|
"keywords": [
|
|
37
58
|
"micro-frontend",
|
|
File without changes
|
|
File without changes
|