Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(html): transform relative path with long base in /index.html #10990

Merged
merged 6 commits into from
Nov 22, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: use path.posix.join when starts with single slash
candy-Tong committed Nov 22, 2022
commit 6144c50a47552dccb600b1dab303689915b26fd6
6 changes: 2 additions & 4 deletions packages/vite/src/node/server/middlewares/indexHtml.ts
Original file line number Diff line number Diff line change
@@ -94,17 +94,15 @@ const processNodeUrl = (
const devBase = config.base
if (startsWithSingleSlashRE.test(url)) {
// prefix with base (dev only, base is never relative)
const fullUrl = joinUrlSegments(devBase, url)
const fullUrl = path.posix.join(devBase, url)
overwriteAttrValue(s, sourceCodeLocation, fullUrl)
} else if (
url.startsWith('.') &&
originalUrl &&
originalUrl !== '/' &&
htmlPath === '/index.html'
) {
// #10990 config.base './' or '' will be changed to `/` in dev mode
// this function is only run in dev mode and config.base is always to be an absolute path.
// we needn't handle config.base './' or ''
// prefix with base (dev only, base is never relative)
const replacer = (url: string) => path.posix.join(devBase, url)

// #3230 if some request url (localhost:3000/a/b) return to fallback html, the relative assets