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: prevent double base in assets on dev mode when assets plugin is applied before html transformation #15345

Closed
wants to merge 1 commit into from
Closed
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
28 changes: 15 additions & 13 deletions packages/vite/src/node/server/middlewares/indexHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,21 @@ const processNodeUrl = (
}

if (
(url[0] === '/' && url[1] !== '/') ||
// #3230 if some request url (localhost:3000/a/b) return to fallback html, the relative assets
// path will add `/a/` prefix, it will caused 404.
//
// skip if url contains `:` as it implies a url protocol or Windows path that we don't want to replace.
//
// rewrite `./index.js` -> `localhost:5173/a/index.js`.
// rewrite `../index.js` -> `localhost:5173/index.js`.
// rewrite `relative/index.js` -> `localhost:5173/a/relative/index.js`.
((url[0] === '.' || isBareRelative(url)) &&
originalUrl &&
originalUrl !== '/' &&
htmlPath === '/index.html')
// avoid duplicate base prefix when applying html transforms after assets plugin
!url.startsWith(config.base) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't do this, or we won't support projects having /root-path/base/ in the fs.
/base/base/file.js is a valid module.

((url[0] === '/' && url[1] !== '/') ||
// #3230 if some request url (localhost:3000/a/b) return to fallback html, the relative assets
// path will add `/a/` prefix, it will caused 404.
//
// skip if url contains `:` as it implies a url protocol or Windows path that we don't want to replace.
//
// rewrite `./index.js` -> `localhost:5173/a/index.js`.
// rewrite `../index.js` -> `localhost:5173/index.js`.
// rewrite `relative/index.js` -> `localhost:5173/a/relative/index.js`.
((url[0] === '.' || isBareRelative(url)) &&
originalUrl &&
originalUrl !== '/' &&
htmlPath === '/index.html'))
) {
url = path.posix.join(config.base, url)
}
Expand Down
Loading