Skip to main content

Integrates Vite resources into a Django web site.

Project description

DjVite

logo

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 djvite to your INSTALLED_APPS django config.
  • Define your static directories:
STATIC_URL = "static/"
STATIC_ROOT = BASE_DIR / 'static'
STATICFILES_DIRS = ['dist']
  • Load the djvite plugin 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 DjVitePlugin to your vite.config.js file:
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:

  • DJVITE dict, with the following keys:
    • DEV_MODE (boolean, default True) When False, resources are resolved using the vite-manifest.json file that list bundle files. This file is generated using vite build.
    • VITE_MANIFEST_PATH (Path | str, default to vite.manifest.json) Location to search for the Vite manifest. Used when DEV_MODE is False.

In vite config plugin:

  • options object for DjVitePlugin.
    • verbose default to false.
    • djangoPort default to DJANGO_PORT environment variable or 8000 if not defined.
    • djangoTemplatesGlob default to the globbing pattern **/templates.
    • manifestPath default to vite.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

djvite-1.2.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

djvite-1.2.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

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

Hashes for djvite-1.2.1.tar.gz
Algorithm Hash digest
SHA256 efb314fdc923886352d770697a143ae8092cfe582da760fc51c356939ce4fbd2
MD5 783fdf97ce5e77811303026e58c9414c
BLAKE2b-256 6570405c1aca7c517cbb132c82dca34a0e0311511604dedef7d24ea675c51a94

See more details on using hashes here.

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

Hashes for djvite-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b048894d1cd1576e9bcf3debcc07c1f95979b63913cd7f191c44adf6cf3047ca
MD5 f2d94df07d9a5b1283f231c8cbc5d100
BLAKE2b-256 cc58e9c77c852956cbccd8d48cacb886feb4b72a17009fa70009f2f6321ba999

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page