web-extend-plugin-vue2 0.1.0 → 0.1.2
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 +40 -10
- package/package.json +1 -1
- package/src/PluginRuntime.js +473 -91
- package/src/bridge.js +32 -4
- package/src/bridge.test.js +38 -29
- package/src/components/ExtensionPoint.vue +4 -0
- package/src/constants.js +4 -1
- package/src/createHostApi.js +106 -11
- package/src/default-runtime-config.js +58 -0
- package/src/dispose-plugin.js +55 -0
- package/src/index.js +6 -0
- package/src/registries.js +10 -2
- package/src/teardown-registry.js +44 -0
package/README.md
CHANGED
|
@@ -1,22 +1,52 @@
|
|
|
1
1
|
# web-extend-plugin-vue2
|
|
2
2
|
|
|
3
|
-
Vue 2.7
|
|
3
|
+
面向 **Vue 2.7** 宿主的 **Web 前端扩展插件**运行时(npm 包)。在浏览器中拉取插件清单、加载入口脚本、向插件注入 **`hostApi`**(路由 / 菜单 / 扩展点 / 受控请求桥等),并提供 **`ExtensionPoint`** 组件在布局中挂载插件视图。与后端清单服务、静态资源目录约定配套使用(如 `extend-plugin-framework` 中的 `web-extend-plugin-server`)。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 安装
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
-
|
|
7
|
+
```bash
|
|
8
|
+
npm add web-extend-plugin-vue2 vue@^2.7 vue-router@^3.6
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 最小接入
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import Vue from 'vue'
|
|
15
|
+
import {
|
|
16
|
+
bootstrapPlugins,
|
|
17
|
+
createHostApi,
|
|
18
|
+
resolveRuntimeOptions,
|
|
19
|
+
ExtensionPoint
|
|
20
|
+
} from 'web-extend-plugin-vue2'
|
|
21
|
+
|
|
22
|
+
Vue.component('ExtensionPoint', ExtensionPoint) // 布局:<ExtensionPoint point-id="..." />
|
|
23
|
+
|
|
24
|
+
const runtime = resolveRuntimeOptions({
|
|
25
|
+
// 按需覆盖,见 defaultWebExtendPluginRuntime
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
bootstrapPlugins(router, (id, r, kit) => createHostApi(id, r, kit), runtime).catch(console.warn)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
清单请求 URL 为 **`manifestBase` + `manifestListPath`**(默认 `/fp-api` + `/api/frontend-plugins`)。工厂请使用 **`(id, r, kit) => createHostApi(id, r, kit)`**,以便 bridge 白名单等配置生效;若仍写 `(id) => createHostApi(id, router)`,仅清单侧配置会随 `runtime` 变化,bridge 仍为内置默认。
|
|
32
|
+
|
|
33
|
+
## 配置与默认值
|
|
34
|
+
|
|
35
|
+
- **优先级**:`bootstrapPlugins` 第三参 → `resolveRuntimeOptions({ ... })` 显式字段 → 环境变量 → 包内 **`defaultWebExtendPluginRuntime`**(可从本包导入)。
|
|
36
|
+
- **完整字段列表**:见仓库 **`src/default-runtime-config.js`** 与 **`src/PluginRuntime.js`** 中的 `resolveRuntimeOptions`。
|
|
37
|
+
- **环境变量**:支持 `VITE_*`;同等含义可用 **`PLUGIN_*`**(将 `VITE_` 换成 `PLUGIN_`)。Vite 使用 `PLUGIN_` 时需在 `vite.config` 设置 `envPrefix: ['VITE_', 'PLUGIN_']`;Webpack 用 `DefinePlugin` 注入 `process.env` 即可。
|
|
9
38
|
|
|
10
|
-
##
|
|
39
|
+
## 卸载
|
|
11
40
|
|
|
12
41
|
```js
|
|
13
|
-
import {
|
|
42
|
+
import { disposeWebPlugin } from 'web-extend-plugin-vue2'
|
|
14
43
|
|
|
15
|
-
|
|
44
|
+
disposeWebPlugin('your.plugin.id')
|
|
16
45
|
```
|
|
17
46
|
|
|
18
|
-
|
|
47
|
+
Vue Router 3 无公开 `removeRoute`,动态路由卸载后可能需整页刷新。
|
|
19
48
|
|
|
20
|
-
##
|
|
49
|
+
## 仓库与协议
|
|
21
50
|
|
|
22
|
-
|
|
51
|
+
- 源码:[extend-plugin-framework / web-extend-plugin-vue2](https://github.com/xtemplus/extend-plugin-framework/tree/master/web-extend-plugin-vue2)
|
|
52
|
+
- 许可证:Apache-2.0
|
package/package.json
CHANGED