Commit b28891d 1 parent 420a517 commit b28891d Copy full SHA for b28891d
File tree 2 files changed +14
-2
lines changed
packages/vsit/src/plugins/vsit
2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " vsit " : patch
3
+ ---
4
+
5
+ fix edit web content not working
Original file line number Diff line number Diff line change @@ -18,7 +18,12 @@ import {
18
18
} from '@/common/utils'
19
19
20
20
import type { AsyncReturnType } from 'type-fest'
21
- import type { Plugin } from 'vite'
21
+ import type { Plugin , ViteDevServer } from 'vite'
22
+
23
+ const invalid = async ( moduleName : string , server : ViteDevServer ) => {
24
+ const module = await server . moduleGraph . getModuleByUrl ( moduleName )
25
+ module && server . moduleGraph . invalidateModule ( module )
26
+ }
22
27
23
28
export const PluginVit = ( ) : Plugin [ ] => {
24
29
let content = ''
@@ -45,6 +50,8 @@ export const PluginVit = (): Plugin[] => {
45
50
return
46
51
}
47
52
if ( url . pathname === '/fake-web-file' && req . method === 'GET' ) {
53
+ // Invalid before transformRequest, make sure transformRequest get latest content from user
54
+ await invalid ( VIRUTAL_WEB_ID , server )
48
55
webContent = ( await server . transformRequest ( VIRUTAL_WEB_ID , { ssr : false } ) ) ?. code ?? ''
49
56
res . setHeader ( 'Content-Type' , 'text/javascript' )
50
57
res . end ( webContent )
@@ -71,7 +78,7 @@ export const PluginVit = (): Plugin[] => {
71
78
} else {
72
79
res . end ( 'ok' )
73
80
}
74
- module && server . moduleGraph . invalidateModule ( module )
81
+ invalid ( VIRUTAL_NODE_ID , server )
75
82
} catch ( e ) {
76
83
console . error ( e )
77
84
}
You can’t perform that action at this time.
0 commit comments