Skip to content

Commit

Permalink
fix(vite): improve hmr handling, #176
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Nov 27, 2021
1 parent e48ffee commit 6682fec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions packages/plugins-common/context.ts
Expand Up @@ -40,11 +40,13 @@ export function createContext<Config extends PluginConfig = PluginConfig>(
invalidations.forEach(cb => cb())
}

async function scan(code: string, id?: string) {
async function extract(code: string, id?: string) {
if (id)
modules.set(id, code)
const len = tokens.size
await uno.applyExtractors(code, id, tokens)
invalidate()
if (tokens.size > len)
invalidate()
}

async function reloadConfig() {
Expand Down Expand Up @@ -75,7 +77,7 @@ export function createContext<Config extends PluginConfig = PluginConfig>(
filter,
reloadConfig,
uno,
extract: scan,
extract,
config,
configFilepath: filepath,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/modes/global/dev.ts
Expand Up @@ -23,7 +23,6 @@ export function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter
const mod = server.moduleGraph.getModuleById(id)
if (!mod)
continue
lastUpdate = Date.now()
server!.moduleGraph.invalidateModule(mod)
}
}
Expand All @@ -32,6 +31,7 @@ export function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter
}

function sendUpdate() {
lastUpdate = Date.now()
for (const server of servers) {
server.ws.send({
type: 'update',
Expand Down

0 comments on commit 6682fec

Please sign in to comment.