Skip to content

Commit

Permalink
chore: update Vite 6 HMR logic for pwa assets
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Nov 15, 2024
1 parent 9093aa1 commit 4d15624
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/plugins/pwa-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,27 @@ export function AssetsPlugin(ctx: PWAPluginContext) {
async handleHotUpdate({ file, server }) {
const pwaAssetsGenerator = await ctx.pwaAssetsGenerator
if (await pwaAssetsGenerator?.checkHotUpdate(file)) {
const modules: ModuleNode[] = []
const head = server.moduleGraph.getModuleById(RESOLVED_PWA_ASSETS_HEAD_VIRTUAL)
head && modules.push(head)
const icons = server.moduleGraph.getModuleById(RESOLVED_PWA_ASSETS_ICONS_VIRTUAL)
icons && modules.push(icons)
if (modules)
return modules

const isVite6 = await ctx.isVite6
if (!isVite6) {
const modules: ModuleNode[] = []
const head = server.moduleGraph.getModuleById(RESOLVED_PWA_ASSETS_HEAD_VIRTUAL)
head && modules.push(head)
const icons = server.moduleGraph.getModuleById(RESOLVED_PWA_ASSETS_ICONS_VIRTUAL)
icons && modules.push(icons)
if (modules.length)
return modules
server.ws.send({ type: 'full-reload' })
return []
}

const modules: import('vite').EnvironmentModuleNode[] = []
const head = server.environments.client.moduleGraph.getModuleById(RESOLVED_PWA_ASSETS_HEAD_VIRTUAL)
head && modules.push(head)
const icons = server.environments.client.moduleGraph.getModuleById(RESOLVED_PWA_ASSETS_ICONS_VIRTUAL)
icons && modules.push(icons)
if (modules.length)
return modules

server.environments.client.hot.send({ type: 'full-reload' })
return []
}
Expand Down

0 comments on commit 4d15624

Please sign in to comment.