Skip to content

Commit

Permalink
fix(build): windows platform build output path error (#17818)
Browse files Browse the repository at this point in the history
  • Loading branch information
btea committed Aug 6, 2024
1 parent cf2f90d commit 6ae0615
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6ae0615

Please sign in to comment.