File tree 3 files changed +14
-20
lines changed
3 files changed +14
-20
lines changed Original file line number Diff line number Diff line change @@ -31,3 +31,10 @@ app.use(DataLoaderPlugin, { router })
31
31
app . use ( router )
32
32
33
33
app . mount ( '#app' )
34
+
35
+ // small logger for navigations, useful to check HMR
36
+ router . isReady ( ) . then ( ( ) => {
37
+ router . beforeEach ( ( to , from ) => {
38
+ console . log ( '🧭' , from . fullPath , '->' , to . fullPath )
39
+ } )
40
+ } )
Original file line number Diff line number Diff line change 1
1
import { type ViteDevServer } from 'vite'
2
- import { ServerContext } from '../../options'
2
+ import { type ServerContext } from '../../options'
3
3
import { MODULE_ROUTES_PATH , asVirtualId } from '../moduleConstants'
4
4
5
5
export function createViteContext ( server : ViteDevServer ) : ServerContext {
@@ -39,28 +39,15 @@ export function createViteContext(server: ViteDevServer): ServerContext {
39
39
} )
40
40
}
41
41
42
- // NOTE: still not working
43
- // based on https://github.com/vuejs/vitepress/blob/1188951785fd2a72f9242d46dc55abb1effd212a/src/node/plugins/localSearchPlugin.ts#L90
44
- // https://github.com/unocss/unocss/blob/f375524d9bca3f2f8b445b322ec0fc3eb124ec3c/packages/vite/src/modes/global/dev.ts#L47-L66
45
-
42
+ /**
43
+ * Triggers HMR for the vue-router/auto-routes module.
44
+ */
46
45
async function updateRoutes ( ) {
47
46
const modId = asVirtualId ( MODULE_ROUTES_PATH )
48
47
const mod = server . moduleGraph . getModuleById ( modId )
49
- if ( ! mod ) {
50
- return
48
+ if ( mod ) {
49
+ return server . reloadModule ( mod )
51
50
}
52
- server . moduleGraph . invalidateModule ( mod )
53
- server . ws . send ( {
54
- type : 'update' ,
55
- updates : [
56
- {
57
- acceptedPath : mod . url ,
58
- path : mod . url ,
59
- timestamp : Date . now ( ) ,
60
- type : 'js-update' ,
61
- } ,
62
- ] ,
63
- } )
64
51
}
65
52
66
53
return {
Original file line number Diff line number Diff line change @@ -246,7 +246,7 @@ export const DEFAULT_OPTIONS = {
246
246
247
247
export interface ServerContext {
248
248
invalidate : ( module : string ) => void
249
- updateRoutes : ( ) => void
249
+ updateRoutes : ( ) => Promise < void >
250
250
reload : ( ) => void
251
251
}
252
252
You can’t perform that action at this time.
0 commit comments