@cdfrd/publish-notification-plugin 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 CHANGED
@@ -1,106 +1,77 @@
1
- # publish-notification-plugin
1
+ # @cdfrd/publish-notification-plugin
2
2
 
3
- Web 端版本更新提醒插件,支持 **Vite** / **Webpack 5**,可接入 qiankun 微前端。仅在 **production** 构建时注入。
3
+ Web 版本更新提醒工具包:**Runtime API** + **薄构建辅助**(只生成 `version.json`,不注入 HTML / 脚本)。本版以 **Vite** 为主。
4
4
 
5
5
  ## 安装
6
6
 
7
7
  ```bash
8
- pnpm add publish-notification-plugin -D
8
+ pnpm add @cdfrd/publish-notification-plugin
9
9
  ```
10
10
 
11
- ## 快速接入
12
-
13
- ### 单体应用
11
+ ## 单体应用(Vite 双零配置)
14
12
 
15
13
  ```ts
16
14
  // vite.config.ts
17
- import { ViteUpdateNotificationPlugin } from 'publish-notification-plugin'
15
+ import { defineConfig } from 'vite'
16
+ import { vitePluginVersion } from '@cdfrd/publish-notification-plugin/vite'
18
17
 
19
18
  export default defineConfig({
20
- plugins: [ViteUpdateNotificationPlugin()],
19
+ plugins: [vitePluginVersion()],
21
20
  })
22
21
  ```
23
22
 
24
- ```js
25
- // webpack.config.js
26
- const { WebpackUpdateNotificationPlugin } = require('publish-notification-plugin')
23
+ ```ts
24
+ // main.ts
25
+ import { createUpdateNotice } from '@cdfrd/publish-notification-plugin'
27
26
 
28
- module.exports = {
29
- plugins: [
30
- new HtmlWebpackPlugin({ template: './index.html' }),
31
- new WebpackUpdateNotificationPlugin(),
32
- ],
33
- }
27
+ createUpdateNotice()
34
28
  ```
35
29
 
36
- 未配置字段走默认:中文、浅色主题、可选更新、右上角、10 分钟轮询。
37
-
38
- ### 微前端(qiankun)
30
+ ## 微前端(qiankun)
39
31
 
40
- 1. **Host 必装**插件(创建 `window.updateNoticeManager`)
41
- 2. 子应用各自安装,并配置 `microApp: { enabled: true, appId }`(`appId` 须与 qiankun `app.name` 一致)
42
- 3. Host 在路由 / `beforeMount` 中调用 `setActiveApp(appId)`,只有当前激活应用会弹窗
32
+ 每个应用各自接入 `vitePluginVersion()` + `createUpdateNotice`;Host 同步 `setActiveApp`。
43
33
 
44
34
  ```ts
45
- // host
46
- ViteUpdateNotificationPlugin({
47
- microApp: { enabled: true, appId: 'host' },
48
- })
35
+ // host/main.ts
36
+ import { createUpdateNotice, getUpdateNotice } from '@cdfrd/publish-notification-plugin'
49
37
 
50
- // 子应用
51
- ViteUpdateNotificationPlugin({
52
- microApp: { enabled: true, appId: 'order-center' },
38
+ createUpdateNotice({
39
+ microApp: { enabled: true, appId: 'host' },
40
+ // 纯壳 Host:disableNotification: true,
53
41
  })
54
- ```
55
42
 
56
- ```ts
57
43
  registerMicroApps(apps, {
58
44
  beforeMount: [
59
45
  (app) => {
60
- window.updateNoticeManager?.setActiveApp(app.name)
46
+ getUpdateNotice()?.setActiveApp(app.name)
61
47
  return Promise.resolve()
62
48
  },
63
49
  ],
64
50
  })
65
-
66
- // Host 自有页(如 /home)按路由同步
67
- window.updateNoticeManager?.setActiveApp('host')
68
51
  ```
69
52
 
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
53
  ```ts
85
- window.updateNoticeManager?.setTheme('dark')
86
- window.updateNoticeManager?.setLocale('en_US')
87
- window.updateNoticeManager?.checkUpdate()
54
+ // order/main.ts
55
+ createUpdateNotice({
56
+ microApp: { enabled: true, appId: 'order-center' },
57
+ })
88
58
  ```
89
59
 
60
+ ## 事后切换语言 / 主题
90
61
 
62
+ ```ts
63
+ import { getUpdateNotice } from '@cdfrd/publish-notification-plugin'
64
+
65
+ getUpdateNotice()?.setLocale('en_US')
66
+ getUpdateNotice()?.setTheme('dark')
67
+ ```
91
68
 
92
69
  ## 本地示例
93
70
 
94
71
  ```bash
95
72
  pnpm install
96
73
  pnpm build
97
- pnpm dev:vite # http://localhost:7100
98
- pnpm dev:webpack # http://localhost:7200
74
+ pnpm dev:vite # Host http://localhost:7100 · 单体 http://localhost:7103
99
75
  ```
100
76
 
101
- 更多示例说明见 [docs/examples.md](./docs/examples.md)。
102
-
103
- # TODO:
104
-
105
- > Webpack插件功能待测试
106
-
77
+ 更多示例见 [docs/examples.md](./docs/examples.md)。