@cdfrd/publish-notification-plugin 0.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 +106 -0
- package/dist/index.cjs +1148 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +61 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +1114 -0
- package/dist/index.js.map +1 -0
- package/dist/types-DaCJHaWX.d.cts +132 -0
- package/dist/types-DaCJHaWX.d.ts +132 -0
- package/dist/version.cjs +102 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.d.cts +13 -0
- package/dist/version.d.ts +13 -0
- package/dist/version.js +75 -0
- package/dist/version.js.map +1 -0
- package/dist/vite.cjs +111 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.d.cts +10 -0
- package/dist/vite.d.ts +10 -0
- package/dist/vite.js +84 -0
- package/dist/vite.js.map +1 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# publish-notification-plugin
|
|
2
|
+
|
|
3
|
+
Web 端版本更新提醒插件,支持 **Vite** / **Webpack 5**,可接入 qiankun 微前端。仅在 **production** 构建时注入。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add publish-notification-plugin -D
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 快速接入
|
|
12
|
+
|
|
13
|
+
### 单体应用
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// vite.config.ts
|
|
17
|
+
import { ViteUpdateNotificationPlugin } from 'publish-notification-plugin'
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
plugins: [ViteUpdateNotificationPlugin()],
|
|
21
|
+
})
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
// webpack.config.js
|
|
26
|
+
const { WebpackUpdateNotificationPlugin } = require('publish-notification-plugin')
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
plugins: [
|
|
30
|
+
new HtmlWebpackPlugin({ template: './index.html' }),
|
|
31
|
+
new WebpackUpdateNotificationPlugin(),
|
|
32
|
+
],
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
未配置字段走默认:中文、浅色主题、可选更新、右上角、10 分钟轮询。
|
|
37
|
+
|
|
38
|
+
### 微前端(qiankun)
|
|
39
|
+
|
|
40
|
+
1. **Host 必装**插件(创建 `window.updateNoticeManager`)
|
|
41
|
+
2. 子应用各自安装,并配置 `microApp: { enabled: true, appId }`(`appId` 须与 qiankun `app.name` 一致)
|
|
42
|
+
3. Host 在路由 / `beforeMount` 中调用 `setActiveApp(appId)`,只有当前激活应用会弹窗
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
// host
|
|
46
|
+
ViteUpdateNotificationPlugin({
|
|
47
|
+
microApp: { enabled: true, appId: 'host' },
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
// 子应用
|
|
51
|
+
ViteUpdateNotificationPlugin({
|
|
52
|
+
microApp: { enabled: true, appId: 'order-center' },
|
|
53
|
+
})
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
registerMicroApps(apps, {
|
|
58
|
+
beforeMount: [
|
|
59
|
+
(app) => {
|
|
60
|
+
window.updateNoticeManager?.setActiveApp(app.name)
|
|
61
|
+
return Promise.resolve()
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
// Host 自有页(如 /home)按路由同步
|
|
67
|
+
window.updateNoticeManager?.setActiveApp('host')
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
## 常用配置与运行时
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
| 场景 | 做法 |
|
|
76
|
+
| --------- | -------------------------------------------------- |
|
|
77
|
+
| 强制更新 | `forcedUpdate: true`,可选 `countdown`(默认 30s) |
|
|
78
|
+
| 改文案 | `notification`(单语言)或 `localeData`(多语言,二者勿同时配) |
|
|
79
|
+
| 纯壳 Host | `disableNotification: true`(只建 Manager,自己不弹窗) |
|
|
80
|
+
| 自定义 UI | `hiddenDefaultNotice: true`,监听 `web_update_notice` |
|
|
81
|
+
| 切换主题 / 语言 | `setTheme('dark' |
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
window.updateNoticeManager?.setTheme('dark')
|
|
86
|
+
window.updateNoticeManager?.setLocale('en_US')
|
|
87
|
+
window.updateNoticeManager?.checkUpdate()
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
## 本地示例
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
pnpm install
|
|
96
|
+
pnpm build
|
|
97
|
+
pnpm dev:vite # http://localhost:7100
|
|
98
|
+
pnpm dev:webpack # http://localhost:7200
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
更多示例说明见 [docs/examples.md](./docs/examples.md)。
|
|
102
|
+
|
|
103
|
+
# TODO:
|
|
104
|
+
|
|
105
|
+
> Webpack插件功能待测试
|
|
106
|
+
|