Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,19 @@ export function renderAssetUrlInJS(
chunk.viteMetadata!.importedAssets.add(cleanUrl(file))
const filename = file + postfix
const replacement = toOutputFilePathInJS(
filename,
encodeURIPath(filename),
'asset',
chunk.fileName,
'js',
config,
toRelativeRuntime,
)

const replacementString =
typeof replacement === 'string'
? JSON.stringify(encodeURIPath(replacement)).slice(1, -1)
? JSON.stringify(replacement).slice(1, -1)
: `"+${replacement.runtime}+"`

s.update(match.index, match.index + full.length, replacementString)
}

Expand All @@ -115,7 +117,7 @@ export function renderAssetUrlInJS(
const [full, hash] = match
const publicUrl = publicAssetUrlMap.get(hash)!.slice(1)
const replacement = toOutputFilePathInJS(
publicUrl,
encodeURIPath(publicUrl),
'public',
chunk.fileName,
'js',
Expand All @@ -124,7 +126,7 @@ export function renderAssetUrlInJS(
)
const replacementString =
typeof replacement === 'string'
? JSON.stringify(encodeURIPath(replacement)).slice(1, -1)
? JSON.stringify(replacement).slice(1, -1)
: `"+${replacement.runtime}+"`
s.update(match.index, match.index + full.length, replacementString)
}
Expand Down
36 changes: 16 additions & 20 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,15 +594,13 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
chunkCSS = chunkCSS.replace(assetUrlRE, (_, fileHash, postfix = '') => {
const filename = this.getFileName(fileHash) + postfix
chunk.viteMetadata!.importedAssets.add(cleanUrl(filename))
return encodeURIPath(
toOutputFilePathInCss(
filename,
'asset',
cssAssetName,
'css',
config,
toRelative,
),
return toOutputFilePathInCss(
encodeURIPath(filename),
'asset',
cssAssetName,
'css',
config,
toRelative,
)
})
// resolve public URL from CSS paths
Expand All @@ -613,15 +611,13 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
)
chunkCSS = chunkCSS.replace(publicAssetUrlRE, (_, hash) => {
const publicUrl = publicAssetUrlMap.get(hash)!.slice(1)
return encodeURIPath(
toOutputFilePathInCss(
publicUrl,
'public',
cssAssetName,
'css',
config,
() => `${relativePathToPublicFromCSS}/${publicUrl}`,
),
return toOutputFilePathInCss(
encodeURIPath(publicUrl),
'public',
cssAssetName,
'css',
config,
() => `${relativePathToPublicFromCSS}/${publicUrl}`,
)
})
}
Expand Down Expand Up @@ -707,7 +703,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
.set(referenceId, { originalName: originalFilename })

const replacement = toOutputFilePathInJS(
this.getFileName(referenceId),
encodeURIPath(this.getFileName(referenceId)),
'asset',
chunk.fileName,
'js',
Expand All @@ -716,7 +712,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
)
const replacementString =
typeof replacement === 'string'
? JSON.stringify(encodeURIPath(replacement)).slice(1, -1)
? JSON.stringify(replacement).slice(1, -1)
: `"+${replacement.runtime}+"`
s.update(start, end, replacementString)
}
Expand Down
18 changes: 8 additions & 10 deletions packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
overwriteAttrValue(
s,
sourceCodeLocation!,
partialEncodeURIPath(toOutputPublicFilePath(url)),
toOutputPublicFilePath(partialEncodeURIPath(url)),
)
}

Expand Down Expand Up @@ -520,7 +520,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
overwriteAttrValue(
s,
getAttrSourceCodeLocation(node, attrKey),
partialEncodeURIPath(toOutputPublicFilePath(url)),
toOutputPublicFilePath(partialEncodeURIPath(url)),
)
} else if (!isExcludedUrl(url)) {
if (
Expand Down Expand Up @@ -640,7 +640,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
s.update(
start,
end,
partialEncodeURIPath(toOutputPublicFilePath(url)),
toOutputPublicFilePath(partialEncodeURIPath(url)),
)
} else if (!isExcludedUrl(url)) {
s.update(
Expand Down Expand Up @@ -909,19 +909,17 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
if (chunk) {
chunk.viteMetadata!.importedAssets.add(cleanUrl(file))
}
return encodeURIPath(toOutputAssetFilePath(file)) + postfix
return toOutputAssetFilePath(encodeURIPath(file)) + postfix
})

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

return encodeURIPath(
urlCanParse(publicAssetPath)
? publicAssetPath
: normalizePath(publicAssetPath),
)
return urlCanParse(publicAssetPath)
? publicAssetPath
: normalizePath(publicAssetPath)
})

if (chunk && canInlineEntry) {
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/plugins/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
const [full, hash] = match
const filename = fileNameHash.get(hash)!
const replacement = toOutputFilePathInJS(
filename,
encodeURIPath(filename),
'asset',
chunk.fileName,
'js',
Expand All @@ -417,7 +417,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
)
const replacementString =
typeof replacement === 'string'
? JSON.stringify(encodeURIPath(replacement)).slice(1, -1)
? JSON.stringify(replacement).slice(1, -1)
: `"+${replacement.runtime}+"`
s.update(match.index, match.index + full.length, replacementString)
}
Expand Down