Skip to content

Commit

Permalink
fix: public asset urls being treated as paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Codex- committed Mar 15, 2023
1 parent e23f690 commit 8276a7e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
getHash,
isDataUrl,
isExternalUrl,
isUrl,
normalizePath,
processSrcSet,
} from '../utils'
Expand Down Expand Up @@ -811,11 +812,13 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
})

result = result.replace(publicAssetUrlRE, (_, fileHash) => {
return normalizePath(
toOutputPublicAssetFilePath(
getPublicAssetFilename(fileHash, config)!,
),
const publicAssetPath = toOutputPublicAssetFilePath(
getPublicAssetFilename(fileHash, config)!,
)

return isUrl(publicAssetPath)
? publicAssetPath
: normalizePath(publicAssetPath)
})

if (chunk && canInlineEntry) {
Expand Down
9 changes: 9 additions & 0 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ function testCaseInsensitiveFS() {
return fs.existsSync(CLIENT_ENTRY.replace('client.mjs', 'cLiEnT.mjs'))
}

export function isUrl(path: string): boolean {
try {
new URL(path)
return true
} catch {
return false
}
}

export const isCaseInsensitiveFS = testCaseInsensitiveFS()

export const isWindows = os.platform() === 'win32'
Expand Down

0 comments on commit 8276a7e

Please sign in to comment.