-
-
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
vite base full url option seems not work in development #3107
Comments
I also have encountered this, and investigated the cause. It seems related to the following code: vite/packages/vite/src/node/config.ts Lines 567 to 572 in d36e10e
Notice how in the above code, the base is converted to only its path name during the serve target. The path (without the host/origin part of the base) is then used in the code below when creating the vue sfc compiler's assetUrlOptions. vite/packages/plugin-vue/src/template.ts Lines 118 to 122 in 0423608
I explored a possible fix by commenting out the logic in resolveBaseUrl that causes this. It got close to working, but the vite web socket connection was made to the incorrect URL. Not sure if that was the correct approach, but it seems that if the web socket logic is updated to support absolute base urls, that everything might work. |
This has been hitting me very badly past few days, hope this gets prioritised.. Thank you! |
Is there some sane workaround without hardcoding ulrs and string replacing? |
@alfeg You can try the Add (e.g.)
|
This is a highly-simplified version of what I use for client projects but it accomplishes the same thing. I typically have a custom global set called export default defineConfig(({ command }) => {
const baseUrl = command === 'serve' ? 'http://localhost:3000/' : '';
return {
define: {
BASE_URL: JSON.stringify(baseUrl),
},
};
}); |
I think this is fixed by #5104 |
@innocenzi awesome! Can confirm that at least in v2.7.12 this bug is no longer reproduced: Added to vite.config {
...
server: {
...
origin: "http://localhost:3000",
}
...
} Now all assets are loading without issues |
@innocenzi @alfeg Sadly I'm not sure what's going on, but I still have a problem with this... Could you tell me what I'm doing wrong? Vite in development is proxied through the backend server, so real URL is Minimal repro, fresh project npm create [email protected]
cd vite-project
vim vite.config.js # add server.origin
npm run dev # vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue()],
server: {origin: "http://localhost:8080/"}
}) Response from dev server <!DOCTYPE html>
<html lang="en">
<head>
<script type="module" src="/@vite/client"></script>
<!-- ... -->
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html> Both @alfeg how does it work for you? |
@Valian The intended purpose behind I would recommend raising a separate ticket with a working example to better understand as it is not related to this issue. |
Describe the bug
vite base full url option seems not work in development
Reproduction
https://github.com/lovetingyuan/vite-base-full-url
System Info
Output of
npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:Used package manager:
yarn
Before submitting the issue, please make sure you do the following
The text was updated successfully, but these errors were encountered: