Skip to content

Commit

Permalink
fix: do not prepend base to double slash urls during dev (#2143)
Browse files Browse the repository at this point in the history
  • Loading branch information
CHOYSEN committed Feb 24, 2021
1 parent 0138ef3 commit 7a1b5c6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/vite/src/node/server/middlewares/indexHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function getHtmlFilename(url: string, server: ViteDevServer) {
}
}

const startsWithSingleSlashRE = /^\/(?!\/)/
const devHtmlHook: IndexHtmlTransformHook = async (
html,
{ path: htmlPath, server }
Expand All @@ -62,7 +63,7 @@ const devHtmlHook: IndexHtmlTransformHook = async (

if (src) {
const url = src.value?.content || ''
if (url.startsWith('/')) {
if (startsWithSingleSlashRE.test(url)) {
// prefix with base
s.overwrite(
src.value!.loc.start.offset,
Expand Down Expand Up @@ -92,7 +93,7 @@ const devHtmlHook: IndexHtmlTransformHook = async (
assetAttrs.includes(p.name)
) {
const url = p.value.content || ''
if (url.startsWith('/')) {
if (startsWithSingleSlashRE.test(url)) {
s.overwrite(
p.value.loc.start.offset,
p.value.loc.end.offset,
Expand Down

0 comments on commit 7a1b5c6

Please sign in to comment.