Skip to content

Commit

Permalink
fix(webpack): HMR not work on Windows (#3495)
Browse files Browse the repository at this point in the history
  • Loading branch information
anyesu committed Jan 25, 2024
1 parent de28b43 commit 2ac03d2
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/webpack/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import process from 'node:process'
import { isAbsolute, normalize } from 'node:path'
import type { UserConfig, UserConfigDefaults } from '@unocss/core'
import type { ResolvedUnpluginOptions, UnpluginOptions } from 'unplugin'
import { createUnplugin } from 'unplugin'
Expand Down Expand Up @@ -155,7 +156,10 @@ export default function WebpackPlugin<Theme extends object>(
lastTokenSize = tokens.size
Array.from(plugin.__vfsModules)
.forEach((id) => {
const path = decodeURIComponent(id.slice(plugin.__virtualModulePrefix.length))
let path = decodeURIComponent(id.slice(plugin.__virtualModulePrefix.length))
// unplugin changes the id in the `load` hook, follow it
// https://github.com/unjs/unplugin/pull/145/files#diff-2b106437404a793ee5b8f3823344656ce880f698d3d8cb6a7cf785e36fb4bf5cR27
path = normalizeAbsolutePath(path)
const layer = resolveLayer(path)
if (!layer)
return
Expand All @@ -182,3 +186,11 @@ function getLayer(id: string) {
}
return layer
}

// https://github.com/unjs/unplugin/pull/145/files#diff-39b2554fd18da165b59a6351b1aafff3714e2a80c1435f2de9706355b4d32351R13-R19
function normalizeAbsolutePath(path: string) {
if (isAbsolute(path))
return normalize(path)
else
return path
}

0 comments on commit 2ac03d2

Please sign in to comment.