Skip to content

Commit

Permalink
fix(html): avoid prepending base URL if it already exists
Browse files Browse the repository at this point in the history
This can happen in SSR mode when a public file is imported as a URL from a JavaScript module and embedded in the HTML.
  • Loading branch information
aleclarson committed Jan 2, 2022
1 parent ce08a06 commit 29a4496
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/vite/src/node/server/middlewares/indexHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ const processNodeUrl = (
const url = node.value?.content || ''
if (startsWithSingleSlashRE.test(url)) {
// prefix with base
s.overwrite(
node.value!.loc.start.offset,
node.value!.loc.end.offset,
`"${config.base + url.slice(1)}"`
)
if (!url.startsWith(config.base))
s.overwrite(
node.value!.loc.start.offset,
node.value!.loc.end.offset,
`"${config.base + url.slice(1)}"`
)
} else if (
url.startsWith('.') &&
originalUrl &&
Expand Down

0 comments on commit 29a4496

Please sign in to comment.