django-vite integrates Vite.js into Django projects, allowing for fast frontend development with Hot Module Replacement (HMR) and efficient production builds. It handles manifest file parsing and asset serving for both development and production environments. The current version is 3.1.0, with frequent patch releases and minor updates.
pip install django-viteVerified import paths — ran on the pinned version, not inferred.
To integrate django-vite, first add 'django_vite' to `INSTALLED_APPS`. Then, configure `DJANGO_VITE` in your settings.py, specifying the `build_dir`, `manifest_path`, and `dev_server_url`. Ensure your Vite project builds its assets to the specified `build_dir`. Finally, include `{% vite_hmr_client %}` and `{% vite_asset 'your_entry_point.js' %}` in your Django templates.
Review the official documentation for the new `DJANGO_VITE` settings structure. For single-app setups, wrap your existing config in `DJANGO_VITE = { 'default': { ... } }`.Either update your Vite `vite.config.js` to use `server: { port: 5173 }` or set `DJANGO_VITE['default']['dev_server_url']` in Django settings to match your custom Vite dev server URL (e.g., `http://localhost:3000`).Always explicitly define `DJANGO_VITE['default']['manifest_path']` (and for other apps if using multi-app config) to `os.path.join(BASE_DIR, 'your_vite_build_output_dir', 'manifest.json')`.
Ensure the `vite_hmr_client` tag is rendered in the `<head>` section, prior to any scripts loaded via `vite_asset`.
Ensure your `STATICFILES_DIRS` or `STATIC_ROOT` configuration includes the Vite build output directory (e.g., `BASE_DIR / 'static' / '.vite'`) so that `collectstatic` can gather the `manifest.json` and other assets. You might also need to adjust `STATIC_URL` and `DJANGO_VITE['default']['static_url_prefix']` to match.