@@ -25,15 +25,18 @@ import {
2525 getTempSrcDescriptor ,
2626} from './utils/descriptorCache'
2727import { 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'
2933import type {
3034 SFCBlock ,
3135 SFCScriptCompileOptions ,
3236 SFCStyleCompileOptions ,
3337 SFCTemplateCompileOptions ,
3438} from 'vue/compiler-sfc'
3539import type * as _compiler from 'vue/compiler-sfc'
36- import type { Server } from '@farmfe/core'
3740
3841export { parseVueRequest , type VueQuery } from './utils/query'
3942
@@ -243,27 +246,27 @@ export const plugin = createUnplugin<Options | undefined, false>(
243246
244247 vite : {
245248 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+ } ,
267270
268271 config ( config ) {
269272 return {
@@ -370,7 +373,39 @@ export const plugin = createUnplugin<Options | undefined, false>(
370373 } ,
371374
372375 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+ } ,
374409 } ,
375410 } ,
376411
0 commit comments