-
Notifications
You must be signed in to change notification settings - Fork 21
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
Unable to import assets in JS #5
Comments
Try changing your setting on settings.py -> |
I'm having the same issue when importing fonts. The problem is that the urls that Vite generates don't have a host, and the browser tries to get them from the Django server instead of the Vite dev server. I can't launch the dev server on the same port, and I don't really know what to do. |
I have made a custom Vite config js file for this and some other cases, it also includes code for building and saving dist files accordingly: https://gist.github.com/GatoVuelta/a87d0007415d3f34d497269ce6dde09b Then, if you use SASS you can import fonts and Vite will automatically look for it both on dev and build. @font-face {
font-family: 'Poppins';
font-style: normal;
src: url('/static/fonts/Poppins-Regular.ttf') format('truetype');
} In the future, I'll make a starter repo that would include all files and configs for an ideal Django + Vite setup. |
The whole problem is that dynamically included files are referenced as |
Turns out it is trivial to solve. Simply set
|
Many thanks for this module - it's made working with Vite in Django much easier for me!
I've converted your example app to a React Vite app, and I'm trying to import and use an image from an assets folder inside
src
:Vite does not complain about the path being wrong (I've tried a few variations) but in the browser the image 404s because the path resolves to:
I believe the problem is that in dev the url should be the port 3000 url, but I'm not sure the best way to address this. Any guidance would be greatly appreciated!
The text was updated successfully, but these errors were encountered: