Integrates Vite resources into a Django web site.
Project description
DjVite
Integrates Vite resources into a Django web site.
Web requests are first served through vite dev server, then either proxified to django dev server or served directly.
This simulates a nginx proxy and wsgi server.
How to use
- Add
djviteto yourINSTALLED_APPSdjango config. - Define your static directories:
STATIC_URL = "static/"
STATIC_ROOT = BASE_DIR / 'static'
STATICFILES_DIRS = ['dist']
- Load the
djviteplugin into your templates:
<html>{% load djvite %}
...
</html>
- Inject any script or link from vite into your template:
{% vite hotreload %}enables vite hot module reload in dev mode{% vite '/src/main.js' %}{% vite '/src/style.css' %}
- Add
DjVitePluginto yourvite.config.jsfile:
import { defineConfig } from 'vite'
import DjVitePlugin from 'djvite'
export default defineConfig({
plugins: [DjVitePlugin({verbose: true})],
})
Notes:
You can add any attributes to the vite tag and it will be added to the final tags.
You can specifiy multiple sources within one vite tag, separate them with spaces.
You can use the get_nginx_config command to generate a working nginx static configuration.
Configuration
In django settings:
DJVITEdict, with the following keys:DEV_MODE(boolean, defaultTrue) WhenFalse, resources are resolved using thevite-manifest.jsonfile that list bundle files. This file is generated usingvite build.VITE_MANIFEST_PATH(Path | str, default tovite.manifest.json) Location to search for the Vite manifest. Used whenDEV_MODEisFalse.
In vite config plugin:
optionsobject forDjVitePlugin.verbosedefault tofalse.djangoPortdefault toDJANGO_PORTenvironment variable or8000if not defined.djangoTemplatesGlobdefault to the globbing pattern**/templates.manifestPathdefault tovite.manifest.json.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file djvite-1.2.1.tar.gz.
File metadata
- Download URL: djvite-1.2.1.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efb314fdc923886352d770697a143ae8092cfe582da760fc51c356939ce4fbd2
|
|
| MD5 |
783fdf97ce5e77811303026e58c9414c
|
|
| BLAKE2b-256 |
6570405c1aca7c517cbb132c82dca34a0e0311511604dedef7d24ea675c51a94
|
File details
Details for the file djvite-1.2.1-py3-none-any.whl.
File metadata
- Download URL: djvite-1.2.1-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b048894d1cd1576e9bcf3debcc07c1f95979b63913cd7f191c44adf6cf3047ca
|
|
| MD5 |
f2d94df07d9a5b1283f231c8cbc5d100
|
|
| BLAKE2b-256 |
cc58e9c77c852956cbccd8d48cacb886feb4b72a17009fa70009f2f6321ba999
|