From 25e3aee7d890e9bc57ca8d91077cb57384228e19 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Sun, 4 Aug 2024 22:33:28 +0800 Subject: [PATCH 1/3] fix(build): windows platform build output path error --- 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, From 01667381c11574514556e9f45d42c4716f75be91 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Mon, 5 Aug 2024 20:04:51 +0800 Subject: [PATCH 2/3] chore: update --- packages/vite/src/node/plugins/css.ts | 9 ++++----- packages/vite/src/node/plugins/html.ts | 6 ++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index dc2964ab57ca8e..7b6db899a51e30 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -594,9 +594,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { const toRelative = (filename: string) => { // relative base + extracted CSS - const relativePath = normalizePath( - path.relative(cssAssetDirname!, filename), - ) + const relativePath = path.relative(cssAssetDirname!, filename) return relativePath[0] === '.' ? relativePath : './' + relativePath } @@ -617,8 +615,9 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { }) // resolve public URL from CSS paths if (encodedPublicUrls) { - const relativePathToPublicFromCSS = normalizePath( - path.relative(cssAssetDirname!, ''), + const relativePathToPublicFromCSS = 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 da548c4f7cf4ba..4a18fdaddf4bbd 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 = normalizePath(path.relative(config.root, id)) + const relativeUrlPath = path.relative(config.root, id) const publicPath = `/${relativeUrlPath}` const publicBase = getBaseInHTML(relativeUrlPath, config) @@ -776,9 +776,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { } for (const [normalizedId, html] of processedHtml) { - const relativeUrlPath = normalizePath( - path.relative(config.root, normalizedId), - ) + const relativeUrlPath = path.relative(config.root, normalizedId) const assetsBase = getBaseInHTML(relativeUrlPath, config) const toOutputFilePath = ( filename: string, From 1bf750d00d9565218124c98d12069c1bfa15ba1f Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Tue, 6 Aug 2024 19:11:32 +0800 Subject: [PATCH 3/3] fix: update --- 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 7b6db899a51e30..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.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.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 4a18fdaddf4bbd..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.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.relative(config.root, normalizedId) + const relativeUrlPath = normalizePath( + path.relative(config.root, normalizedId), + ) const assetsBase = getBaseInHTML(relativeUrlPath, config) const toOutputFilePath = ( filename: string,