-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Avoid adding leading/trailing slash to base #8202
Comments
@X-Y would you try your project with this PR? The idea is that instead of a base token that you later replace, you'll set the base to be relative ( |
@patak-dev If I understand correctly, with this feature I just need to set |
Yes, and it also will take care of assets paths, and public files paths. The PR was released in [email protected] |
Seems to work for me! Not in ie11 though |
Great! I'll close this issue then. For ie11 you'll need to add plugin-legacy. If that still doesn't work, please create a minimal reproduction with it and a new issue so we can check it out. Thanks! |
@patak-dev Could something mentioned above like |
Clear and concise description of the problem
When specifying
base
value in vite.config.js, it is enforced that it starts and ends with a slash if the value is not a "valid" url:vite/packages/vite/src/node/config.ts
Line 597 in 1cc2e2d
In our use case, there are multiple sites consuming the same app. We only build once, where there could use the
base
url would be a token(e.g.#{PUBLIC_PATH}#
) which would be string-replaced for each site. But since Vite enforces a leading slash, I can't use a token at the beginning of the base value.So originally, we would want #{PUBLIC_PATH}#/static/vendor.js -> https://mySite.com/static/vendor.js
But with slash enforcement, it becomes: /#{PUBLIC_PATH}#/static/vendor.js -> /https://mySite.com/static/vendor.js
Suggested solution
In my opinion there shouldn't be an enforcement here. It is up to the individual developer to decide if there should be a leading slash.
Alternative
As an alternative, I suggest adding a flag to the base value. So its type can be
string | {value: string, enforceSlashes: boolean = true}
and if enforceSlashes is set as false, then skip the slash enforcement.Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: