Skip to content

Commit

Permalink
fix(vite): initial load
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 27, 2022
1 parent 7c6d3fb commit c454b56
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions packages/vite/src/modes/global/dev.ts
@@ -1,5 +1,5 @@
import type { Plugin, Update, ViteDevServer, ResolvedConfig as ViteResolvedConfig } from 'vite'
import type { UnocssPluginContext } from '@unocss/core'
import type { GenerateResult, UnocssPluginContext } from '@unocss/core'
import { notNull } from '@unocss/core'
import { LAYER_MARK_ALL, getHash, getPath, resolveId, resolveLayer } from '../../integration'

Expand Down Expand Up @@ -37,9 +37,9 @@ export function GlobalModeDevPlugin({ uno, tokens, affectedModules, onInvalidate
server!.moduleGraph.invalidateModule(mod)
}
}
lastServedHash.clear()
clearTimeout(invalidateTimer)
invalidateTimer = setTimeout(() => {
lastServedHash.clear()
sendUpdate(ids)
}, timer)
}
Expand Down Expand Up @@ -96,15 +96,8 @@ export function GlobalModeDevPlugin({ uno, tokens, affectedModules, onInvalidate
servers.push(_server)

_server.ws.on(WS_EVENT_PREFIX, ([layer, hash]: string[]) => {
if (lastServedHash.get(layer) !== hash) {
if (lastServedHash.get(layer) !== hash)
sendUpdate(entries)
}
else {
setTimeout(() => {
if (lastServedHash.get(layer) !== hash)
sendUpdate(entries)
}, 50)
}
})
},
buildStart() {
Expand Down Expand Up @@ -137,7 +130,15 @@ export function GlobalModeDevPlugin({ uno, tokens, affectedModules, onInvalidate
return null

await Promise.all(tasks)
const result = await uno.generate(tokens)
let result: GenerateResult
let tokensSize = tokens.size
do {
result = await uno.generate(tokens)
// to capture new tokens created during generation
if (tokensSize === tokens.size)
break
tokensSize = tokens.size
} while (true)

const css = layer === LAYER_MARK_ALL
? result.getLayers(undefined, Array.from(entries)
Expand Down

0 comments on commit c454b56

Please sign in to comment.