Skip to content

Commit fefc241

Browse files
committed
auto refresh broswer when saving changes
1 parent 28bf77d commit fefc241

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

vite.config.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { sveltekit } from '@sveltejs/kit/vite';
22
import { defineConfig } from 'vite';
33

44
export default defineConfig({
5-
plugins: [sveltekit()],
5+
// @ts-ignore
6+
plugins: [sveltekit(), AutoRefreshHmr()],
67
ssr: {
78
noExternal: ['@popperjs/core']
89
},
@@ -20,3 +21,19 @@ export default defineConfig({
2021
host: "0.0.0.0",
2122
}
2223
});
24+
25+
function AutoRefreshHmr() {
26+
return {
27+
name: 'auto-refresh',
28+
enforce: 'post',
29+
// @ts-ignore
30+
handleHotUpdate({ file, server }) {
31+
if (file.endsWith('.svelte') || file.endsWith('.js')) {
32+
server.ws.send({
33+
type: 'full-reload',
34+
path: '*'
35+
});
36+
}
37+
}
38+
};
39+
}

0 commit comments

Comments
 (0)