diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 26ba17c192f84e..dc2964ab57ca8e 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -594,7 +594,9 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { const toRelative = (filename: string) => { // relative base + extracted CSS - const relativePath = path.posix.relative(cssAssetDirname!, filename) + const relativePath = normalizePath( + path.relative(cssAssetDirname!, filename), + ) return relativePath[0] === '.' ? relativePath : './' + relativePath } @@ -615,9 +617,8 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { }) // resolve public URL from CSS paths if (encodedPublicUrls) { - const relativePathToPublicFromCSS = path.posix.relative( - cssAssetDirname!, - '', + const relativePathToPublicFromCSS = normalizePath( + path.relative(cssAssetDirname!, ''), ) chunkCSS = chunkCSS.replace(publicAssetUrlRE, (_, hash) => { const publicUrl = publicAssetUrlMap.get(hash)!.slice(1) diff --git a/packages/vite/src/node/plugins/html.ts b/packages/vite/src/node/plugins/html.ts index b7109debc3863a..da548c4f7cf4ba 100644 --- a/packages/vite/src/node/plugins/html.ts +++ b/packages/vite/src/node/plugins/html.ts @@ -330,7 +330,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { async transform(html, id) { if (id.endsWith('.html')) { id = normalizePath(id) - const relativeUrlPath = path.posix.relative(config.root, id) + const relativeUrlPath = normalizePath(path.relative(config.root, id)) const publicPath = `/${relativeUrlPath}` const publicBase = getBaseInHTML(relativeUrlPath, config) @@ -776,7 +776,9 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { } for (const [normalizedId, html] of processedHtml) { - const relativeUrlPath = path.posix.relative(config.root, normalizedId) + const relativeUrlPath = normalizePath( + path.relative(config.root, normalizedId), + ) const assetsBase = getBaseInHTML(relativeUrlPath, config) const toOutputFilePath = ( filename: string,