From 6ae0615416762dd1b89393316308cf8edf115c34 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Tue, 6 Aug 2024 20:43:40 +0800 Subject: [PATCH] fix(build): windows platform build output path error (#17818) --- packages/vite/src/node/plugins/css.ts | 9 +++++---- packages/vite/src/node/plugins/html.ts | 6 ++++-- 2 files changed, 9 insertions(+), 6 deletions(-) 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,