Skip to content
Permalink
Browse files
fix(vite): initial load
  • Loading branch information
antfu committed Sep 27, 2022
1 parent 7c6d3fb commit c454b5611ac9df46292a1b9f49a2fe52f67b4e6c
Showing 1 changed file with 12 additions and 11 deletions.
@@ -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'

@@ -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)
}
@@ -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() {
@@ -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)

0 comments on commit c454b56

Please sign in to comment.