-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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: root import #7224
base: main
Are you sure you want to change the base?
fix: root import #7224
Conversation
|
||
// Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...` | ||
return function viteBaseMiddleware(req, res, next) { | ||
const url = req.url! | ||
const parsed = parseUrl(url) | ||
const path = parsed.pathname || '/' | ||
|
||
if (path.startsWith(root)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should check for path.startsWith(root + base)
, then replace to req.url = url.replace(root + base, '/')
.
If we have root as /home/xxx/
, and base equals to /home/
, the current implementation will fail, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
root + base = /home/xxx/home/
?
In my test case, path will be <root>/[relative path from root]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, gotcha, you are actually trying to fix the other way around.
I thought the bug was that /home/xxx/home/path
was converted into /xxx/home/path
, that seems to be an issue currently.
I don't understand your case, I think that absolute paths will be covered by the rule I proposed. And paths relative to the project root will also work.
The only case that won't be covered is is when you are trying to have an absolute path out of root, but in that case Vite will use /@fs/
, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I update the desc.
If set the base URL to root on Linux and use vue plugin, vue plugin will import css by absolute path. And vite will replace base to
/
, and absolute path startWithbase path
will got a error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@patak-dev the case is
config with
{
base: "/home/"
}
- had absolute path
/home/xxx
- root is
/home/xxx/project
so the request must be /home/xxx/project/assets
(because the request will call by the vue plugin)
and then replace root to be /assets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the bug was that /home/xxx/home/path was converted into /xxx/home/path, that seems to be an issue currently.
Is there a way to reproduce this possible? I've been thinking about it for a long time and can't figure it out. 😂
Description
fix: vitejs/vite-plugin-vue#25
Additional context
If set the base URL to root on Linux and use vue plugin, vue plugin will import css by absolute path. And vite will replace base to
/
, and absolute path startWithbase path
will got a error.this PR analy
req.url(absolute path)
includeroot
will replace it to emtry strings and then it will be a<root>/[relative path]
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes vitejs/vite#123
).