Skip to content

Commit 16e181f

Browse files
committed
docs: update README.md
1 parent 7a171ad commit 16e181f

File tree

11 files changed

+227
-136
lines changed

11 files changed

+227
-136
lines changed

README.md

+23-15
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ export default defineConfig({
143143
})
144144

145145
// other file to listener update event and custom behavior
146-
document.body.addEventListener('plugin_web_update_notice', ({ options, version }) => {
147-
console.log(options)
146+
document.body.addEventListener('plugin_web_update_notice', (e) => {
147+
const { version, options } = e.detail
148148
// write some code, show your custom notification and etc.
149149
alert('System update!')
150150
})
@@ -235,7 +235,8 @@ export interface Options {
235235
/**
236236
* Whether to hide the default notification, if you set it to true, you need to custom behavior by yourself
237237
* ```ts
238-
document.body.addEventListener('plugin_web_update_notice', ({ options, version }) => {
238+
document.body.addEventListener('plugin_web_update_notice', (e) => {
239+
const { version, options } = e.detail
239240
// write some code, show your custom notification and etc.
240241
alert('System update!')
241242
})
@@ -331,12 +332,19 @@ interface Window {
331332

332333
## Q&A
333334

334-
1. `TypeScript` intellisense, if you use `window.pluginWebUpdateNotice_.`
335+
1. `TypeScript` intellisense, if you use `window.pluginWebUpdateNotice_.` or listener custom update event
335336

336337
```ts
337338
// src/shim.d.ts
338-
339-
/// <reference types="@plugin-web-update-notification/core" />
339+
340+
// if you use vite plugin
341+
/// <reference types="@plugin-web-update-notification/vite" />
342+
343+
// if you use umi plugin
344+
/// <reference types="@plugin-web-update-notification/umijs" />
345+
346+
// if you use webpack plugin
347+
/// <reference types="@plugin-web-update-notification/webpack" />
340348
```
341349

342350
2. request `version.json` file get `404 error`.
@@ -345,11 +353,11 @@ interface Window {
345353

346354
```ts
347355
// vite.config.ts
348-
356+
349357
const prod = process.env.NODE_ENV === 'production'
350-
358+
351359
const cdnServerUrl = 'https://foo.com/'
352-
360+
353361
export default defineConfig({
354362
base: prod ? cdnServerUrl : '/',
355363
plugins: [
@@ -365,11 +373,11 @@ interface Window {
365373

366374
```ts
367375
// vite.config.ts
368-
376+
369377
const prod = process.env.NODE_ENV === 'production'
370-
378+
371379
const base = '/folder/' // https://example.com/folder/
372-
380+
373381
export default defineConfig({
374382
base,
375383
plugins: [
@@ -388,7 +396,7 @@ interface Window {
388396
```ts
389397
// refresh button click event, if you set it, it will cover the default event (location.reload())
390398
window.pluginWebUpdateNotice_.onClickRefresh = (version) => { alert(`click refresh btn: ${version}`) }
391-
399+
392400
// dismiss button click event, if you set it, it will cover the default event (dismissUpdate())
393401
window.pluginWebUpdateNotice_.onClickDismiss = (version) => { alert(`click dismiss btn: ${version}`) }
394402
```
@@ -399,7 +407,7 @@ interface Window {
399407

400408
```html
401409
<!-- notification html content -->
402-
410+
403411
<div class="plugin-web-update-notice-anchor">
404412
<div class="plugin-web-update-notice">
405413
<div class="plugin-web-update-notice-content" data-cy="notification-content">
@@ -430,7 +438,7 @@ interface Window {
430438
})
431439
```
432440

433-
441+
434442
## License
435443

436444
[MIT](./LICENSE)

README.zh-CN.md

+22-12
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ document.body.addEventListener('plugin_web_update_notice', ({ options, version }
151151

152152
### Umijs
153153

154+
不支持 `umi2`, `umi2` 可以尝试下通过 `chainWebpack` 配置 `webpack` 插件。
155+
154156
```ts
155157
// .umirc.ts
156158
import { defineConfig } from 'umi'
@@ -234,7 +236,8 @@ export interface Options {
234236
/**
235237
* Whether to hide the default notification, if you set it to true, you need to custom behavior by yourself
236238
* ```ts
237-
document.body.addEventListener('plugin_web_update_notice', ({ options, version }) => {
239+
document.body.addEventListener('plugin_web_update_notice', (e) => {
240+
const { version, options } = e.detail
238241
// write some code, show your custom notification and etc.
239242
alert('System update!')
240243
})
@@ -331,12 +334,19 @@ interface Window {
331334

332335
## Q&A
333336

334-
1. `TypeScript` 的智能提示, 如果你想使用 `window.pluginWebUpdateNotice_.`
337+
1. `TypeScript` 的智能提示, 如果你想使用 `window.pluginWebUpdateNotice_.` 或监听自定义更新事件
335338

336339
```ts
337340
// src/shim.d.ts
338341

339-
/// <reference types="@plugin-web-update-notification/core" />
342+
// if you use vite plugin
343+
/// <reference types="@plugin-web-update-notification/vite" />
344+
345+
// if you use umi plugin
346+
/// <reference types="@plugin-web-update-notification/umijs" />
347+
348+
// if you use webpack plugin
349+
/// <reference types="@plugin-web-update-notification/webpack" />
340350
```
341351

342352
2. 请求 `version.json` 文件提示 `404 error`
@@ -345,11 +355,11 @@ interface Window {
345355

346356
```ts
347357
// vite.config.ts
348-
358+
349359
const prod = process.env.NODE_ENV === 'production'
350-
360+
351361
const cdnServerUrl = 'https://foo.com/'
352-
362+
353363
export default defineConfig({
354364
base: prod ? cdnServerUrl : '/',
355365
plugins: [
@@ -365,11 +375,11 @@ interface Window {
365375

366376
```ts
367377
// vite.config.ts
368-
378+
369379
const prod = process.env.NODE_ENV === 'production'
370-
380+
371381
const base = '/folder/' // https://example.com/folder/
372-
382+
373383
export default defineConfig({
374384
base,
375385
plugins: [
@@ -388,7 +398,7 @@ interface Window {
388398
```ts
389399
// refresh button click event, if you set it, it will cover the default event (location.reload())
390400
window.pluginWebUpdateNotice_.onClickRefresh = (version) => { alert(`click refresh btn: ${version}`) }
391-
401+
392402
// dismiss button click event, if you set it, it will cover the default event (dismissUpdate())
393403
window.pluginWebUpdateNotice_.onClickDismiss = (version) => { alert(`click dismiss btn: ${version}`) }
394404
```
@@ -399,7 +409,7 @@ interface Window {
399409

400410
```html
401411
<!-- notification html content -->
402-
412+
403413
<div class="plugin-web-update-notice-anchor">
404414
<div class="plugin-web-update-notice">
405415
<div class="plugin-web-update-notice-content" data-cy="notification-content">
@@ -430,7 +440,7 @@ interface Window {
430440
})
431441
```
432442

433-
443+
434444

435445
## 文章
436446
* https://juejin.cn/post/7209234917288886331

packages/core/README.md

+23-15
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ export default defineConfig({
143143
})
144144

145145
// other file to listener update event and custom behavior
146-
document.body.addEventListener('plugin_web_update_notice', ({ options, version }) => {
147-
console.log(options)
146+
document.body.addEventListener('plugin_web_update_notice', (e) => {
147+
const { version, options } = e.detail
148148
// write some code, show your custom notification and etc.
149149
alert('System update!')
150150
})
@@ -235,7 +235,8 @@ export interface Options {
235235
/**
236236
* Whether to hide the default notification, if you set it to true, you need to custom behavior by yourself
237237
* ```ts
238-
document.body.addEventListener('plugin_web_update_notice', ({ options, version }) => {
238+
document.body.addEventListener('plugin_web_update_notice', (e) => {
239+
const { version, options } = e.detail
239240
// write some code, show your custom notification and etc.
240241
alert('System update!')
241242
})
@@ -331,12 +332,19 @@ interface Window {
331332

332333
## Q&A
333334

334-
1. `TypeScript` intellisense, if you use `window.pluginWebUpdateNotice_.`
335+
1. `TypeScript` intellisense, if you use `window.pluginWebUpdateNotice_.` or listener custom update event
335336

336337
```ts
337338
// src/shim.d.ts
338-
339-
/// <reference types="@plugin-web-update-notification/core" />
339+
340+
// if you use vite plugin
341+
/// <reference types="@plugin-web-update-notification/vite" />
342+
343+
// if you use umi plugin
344+
/// <reference types="@plugin-web-update-notification/umijs" />
345+
346+
// if you use webpack plugin
347+
/// <reference types="@plugin-web-update-notification/webpack" />
340348
```
341349

342350
2. request `version.json` file get `404 error`.
@@ -345,11 +353,11 @@ interface Window {
345353

346354
```ts
347355
// vite.config.ts
348-
356+
349357
const prod = process.env.NODE_ENV === 'production'
350-
358+
351359
const cdnServerUrl = 'https://foo.com/'
352-
360+
353361
export default defineConfig({
354362
base: prod ? cdnServerUrl : '/',
355363
plugins: [
@@ -365,11 +373,11 @@ interface Window {
365373

366374
```ts
367375
// vite.config.ts
368-
376+
369377
const prod = process.env.NODE_ENV === 'production'
370-
378+
371379
const base = '/folder/' // https://example.com/folder/
372-
380+
373381
export default defineConfig({
374382
base,
375383
plugins: [
@@ -388,7 +396,7 @@ interface Window {
388396
```ts
389397
// refresh button click event, if you set it, it will cover the default event (location.reload())
390398
window.pluginWebUpdateNotice_.onClickRefresh = (version) => { alert(`click refresh btn: ${version}`) }
391-
399+
392400
// dismiss button click event, if you set it, it will cover the default event (dismissUpdate())
393401
window.pluginWebUpdateNotice_.onClickDismiss = (version) => { alert(`click dismiss btn: ${version}`) }
394402
```
@@ -399,7 +407,7 @@ interface Window {
399407

400408
```html
401409
<!-- notification html content -->
402-
410+
403411
<div class="plugin-web-update-notice-anchor">
404412
<div class="plugin-web-update-notice">
405413
<div class="plugin-web-update-notice-content" data-cy="notification-content">
@@ -430,7 +438,7 @@ interface Window {
430438
})
431439
```
432440

433-
441+
434442
## License
435443

436444
[MIT](./LICENSE)

packages/core/README.zh-CN.md

+22-12
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ document.body.addEventListener('plugin_web_update_notice', ({ options, version }
151151

152152
### Umijs
153153

154+
不支持 `umi2`, `umi2` 可以尝试下通过 `chainWebpack` 配置 `webpack` 插件。
155+
154156
```ts
155157
// .umirc.ts
156158
import { defineConfig } from 'umi'
@@ -234,7 +236,8 @@ export interface Options {
234236
/**
235237
* Whether to hide the default notification, if you set it to true, you need to custom behavior by yourself
236238
* ```ts
237-
document.body.addEventListener('plugin_web_update_notice', ({ options, version }) => {
239+
document.body.addEventListener('plugin_web_update_notice', (e) => {
240+
const { version, options } = e.detail
238241
// write some code, show your custom notification and etc.
239242
alert('System update!')
240243
})
@@ -331,12 +334,19 @@ interface Window {
331334

332335
## Q&A
333336

334-
1. `TypeScript` 的智能提示, 如果你想使用 `window.pluginWebUpdateNotice_.`
337+
1. `TypeScript` 的智能提示, 如果你想使用 `window.pluginWebUpdateNotice_.` 或监听自定义更新事件
335338

336339
```ts
337340
// src/shim.d.ts
338341

339-
/// <reference types="@plugin-web-update-notification/core" />
342+
// if you use vite plugin
343+
/// <reference types="@plugin-web-update-notification/vite" />
344+
345+
// if you use umi plugin
346+
/// <reference types="@plugin-web-update-notification/umijs" />
347+
348+
// if you use webpack plugin
349+
/// <reference types="@plugin-web-update-notification/webpack" />
340350
```
341351

342352
2. 请求 `version.json` 文件提示 `404 error`
@@ -345,11 +355,11 @@ interface Window {
345355

346356
```ts
347357
// vite.config.ts
348-
358+
349359
const prod = process.env.NODE_ENV === 'production'
350-
360+
351361
const cdnServerUrl = 'https://foo.com/'
352-
362+
353363
export default defineConfig({
354364
base: prod ? cdnServerUrl : '/',
355365
plugins: [
@@ -365,11 +375,11 @@ interface Window {
365375

366376
```ts
367377
// vite.config.ts
368-
378+
369379
const prod = process.env.NODE_ENV === 'production'
370-
380+
371381
const base = '/folder/' // https://example.com/folder/
372-
382+
373383
export default defineConfig({
374384
base,
375385
plugins: [
@@ -388,7 +398,7 @@ interface Window {
388398
```ts
389399
// refresh button click event, if you set it, it will cover the default event (location.reload())
390400
window.pluginWebUpdateNotice_.onClickRefresh = (version) => { alert(`click refresh btn: ${version}`) }
391-
401+
392402
// dismiss button click event, if you set it, it will cover the default event (dismissUpdate())
393403
window.pluginWebUpdateNotice_.onClickDismiss = (version) => { alert(`click dismiss btn: ${version}`) }
394404
```
@@ -399,7 +409,7 @@ interface Window {
399409

400410
```html
401411
<!-- notification html content -->
402-
412+
403413
<div class="plugin-web-update-notice-anchor">
404414
<div class="plugin-web-update-notice">
405415
<div class="plugin-web-update-notice-content" data-cy="notification-content">
@@ -430,7 +440,7 @@ interface Window {
430440
})
431441
```
432442

433-
443+
434444

435445
## 文章
436446
* https://juejin.cn/post/7209234917288886331

0 commit comments

Comments
 (0)