Skip to content

Commit

Permalink
chore: update code
Browse files Browse the repository at this point in the history
  • Loading branch information
ErKeLost committed Dec 26, 2024
1 parent bd6b424 commit 8d2a511
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 25 deletions.
2 changes: 1 addition & 1 deletion examples/webpack/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const msg = ref('')
<template>
<div>
<h1 class="text-red">Hello world</h1>
<h2>{{ msg }}</h2>
<h2>{{ msg }}</h2>222
<input v-model="msg" type="text" />
</div>
</template>
Expand Down
83 changes: 59 additions & 24 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ import {
getTempSrcDescriptor,
} from './utils/descriptorCache'
import { parseVueRequest } from './utils/query'
import type { PluginLoadHookParam, ResolvedUserConfig } from '@farmfe/core'
import type {
PluginLoadHookParam,

Check failure on line 29 in src/core/index.ts

View workflow job for this annotation

GitHub Actions / lint

'PluginLoadHookParam' is declared but never used.
ResolvedUserConfig,
Server,
} from '@farmfe/core'

Check failure on line 32 in src/core/index.ts

View workflow job for this annotation

GitHub Actions / lint

Cannot find module '@farmfe/core' or its corresponding type declarations.
import type {
SFCBlock,
SFCScriptCompileOptions,
SFCStyleCompileOptions,
SFCTemplateCompileOptions,
} from 'vue/compiler-sfc'
import type * as _compiler from 'vue/compiler-sfc'
import type { Server } from '@farmfe/core'

export { parseVueRequest, type VueQuery } from './utils/query'

Expand Down Expand Up @@ -243,27 +246,27 @@ export const plugin = createUnplugin<Options | undefined, false>(

vite: {
api,
// handleHotUpdate(ctx) {
// ctx.server.ws.send({
// type: 'custom',
// event: 'file-changed',
// data: { file: normalizePath(ctx.file) },
// })

// if (options.value.compiler.invalidateTypeCache) {
// options.value.compiler.invalidateTypeCache(ctx.file)
// }
// if (typeDepToSFCMap.has(ctx.file)) {
// return handleTypeDepChange(typeDepToSFCMap.get(ctx.file)!, ctx)
// }
// if (filter.value(ctx.file)) {
// return handleHotUpdate(
// ctx,
// options.value,
// customElementFilter.value(ctx.file),
// )
// }
// },
async handleHotUpdate(ctx) {
// console.log(ctx);
ctx.server.ws.send({
type: 'custom',
event: 'file-changed',
data: { file: normalizePath(ctx.file) },
})
if (options.value.compiler.invalidateTypeCache) {
options.value.compiler.invalidateTypeCache(ctx.file)
}
if (typeDepToSFCMap.has(ctx.file)) {
return handleTypeDepChange(typeDepToSFCMap.get(ctx.file)!, ctx)
}
if (filter.value(ctx.file)) {
return handleHotUpdate(
ctx,
options.value,
customElementFilter.value(ctx.file),
)

Check failure on line 267 in src/core/index.ts

View workflow job for this annotation

GitHub Actions / lint

Parameter 'config' implicitly has an 'any' type.
}
},

config(config) {
return {
Expand Down Expand Up @@ -370,7 +373,39 @@ export const plugin = createUnplugin<Options | undefined, false>(
},

configureServer(server: Server) {
options.value.devServer = server
const {
config: {
compilation: {
output: { publicPath },
},
},
} = server
options.value.devServer = Object.assign(server, {
config: { ...server.config, base: publicPath },
})
},

updateModules: {
executor(ctx) {
options.value.devServer.ws.send({
type: 'custom',
event: 'file-changed',
data: { file: normalizePath(ctx.file) },
})
if (options.value.compiler.invalidateTypeCache) {
options.value.compiler.invalidateTypeCache(ctx.file)
}
if (typeDepToSFCMap.has(ctx.file)) {
return handleTypeDepChange(typeDepToSFCMap.get(ctx.file)!, ctx)
}
if (filter.value(ctx.file)) {
return handleHotUpdate(
ctx,
options.value,
customElementFilter.value(ctx.file),
)
}
},
},
},

Expand Down

0 comments on commit 8d2a511

Please sign in to comment.