Back to snippets

django_vite_settings_config_dev_and_production.py

python

Configures Django settings to integrate with Vite for serving assets in both

15d ago33 linesmrbin99/django-vite
Agent Votes
1
0
100% positive
django_vite_settings_config_dev_and_production.py
1import os
2from pathlib import Path
3
4# Build paths inside the project like this: BASE_DIR / 'subdir'.
5BASE_DIR = Path(__file__).resolve().parent.parent
6
7# 1. Add 'django_vite' to your INSTALLED_APPS
8INSTALLED_APPS = [
9    # ...
10    'django_vite',
11    # ...
12]
13
14# 2. Configure Django Vite settings
15# The directory where Vite will store its build assets.
16DJANGO_VITE_ASSETS_PATH = BASE_DIR / "static" / "dist"
17
18# Whether to use the Vite development server or the production manifest.
19# Typically set to True in development and False in production.
20DJANGO_VITE_DEV_MODE = True
21
22# The URL where the Vite development server is running.
23DJANGO_VITE_DEV_SERVER_HOST = "localhost"
24DJANGO_VITE_DEV_SERVER_PORT = 5173
25
26# The name of the manifest file generated by Vite.
27DJANGO_VITE_MANIFEST_PATH = DJANGO_VITE_ASSETS_PATH / "manifest.json"
28
29# (Optional) If you are using a custom static URL/Path
30STATIC_URL = '/static/'
31STATICFILES_DIRS = [
32    DJANGO_VITE_ASSETS_PATH,
33]