-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Asset Not Loaded When Integrating With Existing Backend #7778
Comments
It is mentioned here. Or do you have a different situation?
|
I am sorry, I think I might have misunderstood the term "working directory". I understood it as Vite and my own server should start in the same working directory, whereas I think what the documentation is saying is I need to redirect static file requests to vite. It's all fixed now! |
Do you think it's a good idea for me to open a pull request and change the wording a bit? |
Yes it can be solved with proxying static file requests to vite. IIUC it can also be solved with serving static files from the custom backend server. It would be great to have a PR. |
I'm also running into this issue with a Laravel backend server. Would it be reasonable in dev mode for Vite to include the full URL, instead of just the path? E.g. This would avoid the need to proxy or serve the project root. Laravel is already serving a I have tried specifying |
I think you are just missing // vite.config.ts
import { defineConfig } from 'vite'
export default defineConfig({
server: {
origin: 'http://localhost:4000',
},
}) Reproduction: https://stackblitz.com/edit/vitejs-vite-4qrrx3?file=vite.config.ts |
I have opened a PR at #8103 to incorporate the discussion in this issue. |
Co-authored-by: Enzo Innocenzi <[email protected]>
I don't think Hopefully this explains the issue I'm trying to solve: Example Laravel project structure:
Example Vite config: {
base: command === 'build' ? 'build' : '',
publicDir: false,
build: {
manifest: true,
outDir: 'public/build',
rollupOptions: {
input: 'resources/js/app.js'
}
}
} Welcome.vue: <!--
Vite should leave absolute paths as-is so nginx can serve them from the
public directory.
The PR at https://github.com/vitejs/vite/pull/6779 hopefully addresses this
but I haven't tested yet.
-->
<img src="/images/taylor.jpg" />
<!--
Vite resolves this from disk and rewrites the URL.
In build mode, the file is versioned in the outDir (e.g. public/build) and
the URL is correctly rewritten as `/build/assets/abigail.123456.js` which
nginx can serve.
In serve mode, Vite serves the file at
`http://localhost:3000/images/abigail.jpg` but the URL is only rewritten as
`/images/abigail.jpg`, so the browser makes the request to the backend
server where the file does not exist publicly. Setting `server.origin` to
the backend server would only make this unwanted behaviour explicit.
Ideally, this would be rewritten to include the full URL to the Vite server
(`http://localhost:3000/images/abigail.jpg`).
-->
<img src="../images/abigail.jpg" />
|
Describe the bug
When I import an asset
audio
resolves to something likebase/**/do.mp3
in development mode. I am integrating Vite into an existing backend. The backend is running atlocalhost:4000
and vite is running atlocalhost:3000
. So during development, the existing backend atlocalhost:4000
does not yet havebase/**/do.mp3
.For production though, it works fine,
vite build
will produce the files that the existing backend atlocalhost:4000
will be able to serveI think that this should be noted in the docs or maybe
audio
can resolve to something likelocalhost:3000/base/**/do.mp3
insteadReproduction
https://stackblitz.com/edit/vitejs-vite-kkwd9h?file=src/main.js
System Info
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: