Skip to main content

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 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.
    • djangoPatterns default to folder and html pattern files ['^.*/$', '^.*\.html$'].
    • 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.0.0.tar.gz (7.1 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.0.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file djvite-1.0.0.tar.gz.

File metadata

  • Download URL: djvite-1.0.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for djvite-1.0.0.tar.gz
Algorithm Hash digest
SHA256 64a215ce932a9d0f4a41e40768d9867a82f61f19d31da3ab8f18a24cade2ce73
MD5 ceea97ee21f9592205f44e26427ea501
BLAKE2b-256 b766935694baedca2898867acfe917668f46a0054e1b815426bc4d804afc1c81

See more details on using hashes here.

File details

Details for the file djvite-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: djvite-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for djvite-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71f8f3a62a082a2d19e77aeeb6e0b3018e5b58a911e753498aa90e063310aa5d
MD5 97a713af58236d204881f9c6add88008
BLAKE2b-256 bfb62bc3d8c296f23849b5b3a9606926ff7aa584b8dc8b83c87afd99e1175aad

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