@@ -25,15 +25,18 @@ import {
25
25
getTempSrcDescriptor ,
26
26
} from './utils/descriptorCache'
27
27
import { parseVueRequest } from './utils/query'
28
- import type { PluginLoadHookParam , ResolvedUserConfig } from '@farmfe/core'
28
+ import type {
29
+ PluginLoadHookParam ,
30
+ ResolvedUserConfig ,
31
+ Server ,
32
+ } from '@farmfe/core'
29
33
import type {
30
34
SFCBlock ,
31
35
SFCScriptCompileOptions ,
32
36
SFCStyleCompileOptions ,
33
37
SFCTemplateCompileOptions ,
34
38
} from 'vue/compiler-sfc'
35
39
import type * as _compiler from 'vue/compiler-sfc'
36
- import type { Server } from '@farmfe/core'
37
40
38
41
export { parseVueRequest , type VueQuery } from './utils/query'
39
42
@@ -243,27 +246,27 @@ export const plugin = createUnplugin<Options | undefined, false>(
243
246
244
247
vite : {
245
248
api,
246
- // handleHotUpdate(ctx) {
247
- // ctx.server.ws.send({
248
- // type: 'custom',
249
- // event : 'file-changed ',
250
- // data: { file: normalizePath(ctx.file) } ,
251
- // })
252
-
253
- // if (options.value.compiler.invalidateTypeCache) {
254
- // options.value.compiler.invalidateTypeCache(ctx.file)
255
- // }
256
- // if (typeDepToSFCMap.has(ctx.file)) {
257
- // return handleTypeDepChange(typeDepToSFCMap.get(ctx.file)!, ctx)
258
- // }
259
- // if (filter.value(ctx.file)) {
260
- // return handleHotUpdate(
261
- // ctx,
262
- // options.value,
263
- // customElementFilter.value(ctx.file),
264
- // )
265
- // }
266
- // },
249
+ async handleHotUpdate ( ctx ) {
250
+ // console.log(ctx);
251
+ ctx . server . ws . send ( {
252
+ type : 'custom ' ,
253
+ event : ' file-changed' ,
254
+ data : { file : normalizePath ( ctx . file ) } ,
255
+ } )
256
+ if ( options . value . compiler . invalidateTypeCache ) {
257
+ options . value . compiler . invalidateTypeCache ( ctx . file )
258
+ }
259
+ if ( typeDepToSFCMap . has ( ctx . file ) ) {
260
+ return handleTypeDepChange ( typeDepToSFCMap . get ( ctx . file ) ! , ctx )
261
+ }
262
+ if ( filter . value ( ctx . file ) ) {
263
+ return handleHotUpdate (
264
+ ctx ,
265
+ options . value ,
266
+ customElementFilter . value ( ctx . file ) ,
267
+ )
268
+ }
269
+ } ,
267
270
268
271
config ( config ) {
269
272
return {
@@ -370,7 +373,39 @@ export const plugin = createUnplugin<Options | undefined, false>(
370
373
} ,
371
374
372
375
configureServer ( server : Server ) {
373
- options . value . devServer = server
376
+ const {
377
+ config : {
378
+ compilation : {
379
+ output : { publicPath } ,
380
+ } ,
381
+ } ,
382
+ } = server
383
+ options . value . devServer = Object . assign ( server , {
384
+ config : { ...server . config , base : publicPath } ,
385
+ } )
386
+ } ,
387
+
388
+ updateModules : {
389
+ executor ( ctx ) {
390
+ options . value . devServer . ws . send ( {
391
+ type : 'custom' ,
392
+ event : 'file-changed' ,
393
+ data : { file : normalizePath ( ctx . file ) } ,
394
+ } )
395
+ if ( options . value . compiler . invalidateTypeCache ) {
396
+ options . value . compiler . invalidateTypeCache ( ctx . file )
397
+ }
398
+ if ( typeDepToSFCMap . has ( ctx . file ) ) {
399
+ return handleTypeDepChange ( typeDepToSFCMap . get ( ctx . file ) ! , ctx )
400
+ }
401
+ if ( filter . value ( ctx . file ) ) {
402
+ return handleHotUpdate (
403
+ ctx ,
404
+ options . value ,
405
+ customElementFilter . value ( ctx . file ) ,
406
+ )
407
+ }
408
+ } ,
374
409
} ,
375
410
} ,
376
411
0 commit comments