Skip to content

Commit fbe9f99

Browse files
committed
docs: add onWatched hook reference
1 parent 0bcd594 commit fbe9f99

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

docs/reference/plugin-api.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,18 @@ module.exports = {
276276

277277
This hook will be invoked once VuePress app has finished preparation.
278278

279+
### onWatched
280+
281+
- Type: `(app: App, watchers: Closable[], restart: () => Promise<void>) => void | Promise<void>`
282+
283+
- Details:
284+
285+
This hook will be invoked once VuePress app has started dev-server and watched files change.
286+
287+
The `watchers` is an array of file watchers. When changing config file, the dev command will be restarted and those watchers will be closed. If you are adding new watchers in this hook, you should push your watchers to the `watchers` array, so that they can be closed correctly when restarting.
288+
289+
The `restart` is a method to restart the dev command. When calling this method, the `watchers` array will be closed automatically.
290+
279291
### onGenerated
280292

281293
- Type: `(app: App) => void | Promise<void>`

docs/zh/reference/plugin-api.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,18 @@ module.exports = {
276276

277277
该 Hook 会在 VuePress App 完成文件准备后被立即调用。
278278

279+
### onWatched
280+
281+
- 类型: `(app: App, watchers: Closable[], restart: () => Promise<void>) => void | Promise<void>`
282+
283+
- 详情:
284+
285+
该 Hook 会在 VuePress App 启动开发服务器并开始监听文件修改后被调用。
286+
287+
`watchers` 是一个文件监听器的数组。在修改配置文件导致重启 dev 命令时,这些监听器会被自动关闭。如果你在当前 Hook 中添加了新的监听器,你应该把它们也加入到这个数组中,确保在重启 dev 命令时它们能被正确关闭。
288+
289+
`restart` 方法用来重启 dev 命令。调用该方法时, `watchers` 数组中的监听器也会被自动关闭。
290+
279291
### onGenerated
280292

281293
- 类型: `(app: App) => void | Promise<void>`

0 commit comments

Comments
 (0)