You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/guide/api-hmr.md
+13
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,7 @@ interface ViteHotContext {
29
29
):void
30
30
31
31
dispose(cb: (data:any) =>void):void
32
+
prune(cb: (data:any) =>void):void
32
33
decline():void
33
34
invalidate(message?:string):void
34
35
@@ -115,6 +116,18 @@ if (import.meta.hot) {
115
116
}
116
117
```
117
118
119
+
## `hot.prune(cb)`
120
+
121
+
Register a callback that will call when the module is no longer imported on the page. This can be used to clean up side effects like style injections. Vite already does this for `.css` imports.
122
+
123
+
```js
124
+
if (import.meta.hot) {
125
+
import.meta.hot.prune((data) => {
126
+
// cleanup side effect
127
+
})
128
+
}
129
+
```
130
+
118
131
## `hot.data`
119
132
120
133
The `import.meta.hot.data` object is persisted across different instances of the same updated module. It can be used to pass on information from a previous version of the module to the next one.
0 commit comments