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.
    • 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.1.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.1.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: djvite-1.1.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.1.0.tar.gz
Algorithm Hash digest
SHA256 5f3f1550bb92637aa5ab4c63e57cb8167749d07d2e3b760e4f8e2f910134c546
MD5 a3f2496ecd877e3ec606c5be1228fd43
BLAKE2b-256 3591d5690d5175179af45610e6aac8d0807eef6aa93b73dae2752e1009df9a8a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: djvite-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61fe9608b5263d7d88eda1dca0908a8a0de5cf068a204cdf9e4af070269951ed
MD5 56cbcba200bde40559d6583804ccaa2d
BLAKE2b-256 087aa7d4ca1b8dbf786b85f43a581543029a8e3c60074d1303be5ea0ed786d29

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