diff --git a/packages/vite/src/node/plugins/html.ts b/packages/vite/src/node/plugins/html.ts
index bfa2fe9c897868..eb61512a310888 100644
--- a/packages/vite/src/node/plugins/html.ts
+++ b/packages/vite/src/node/plugins/html.ts
@@ -588,7 +588,6 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
}
}
- const shortEmitName = path.posix.relative(config.root, id)
// no use assets plugin because it will emit file
let match: RegExpExecArray | null
let s: MagicString | undefined
@@ -605,8 +604,9 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
if (s) {
result = s.toString()
}
+ const relativeUrlPath = path.posix.relative(config.root, id)
result = await applyHtmlTransforms(result, postHooks, {
- path: '/' + shortEmitName,
+ path: '/' + relativeUrlPath,
filename: id,
bundle,
chunk
@@ -621,6 +621,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
delete bundle[chunk.fileName]
}
+ const shortEmitName = path.relative(config.root, id)
this.emitFile({
type: 'asset',
fileName: shortEmitName,