feat(src/djinit/templates): AddVite‑based asset pipeline support
- New Features - Insert manifest_path and static_url_prefix into base settings for Vite output - Enable/disable dev mode via DJANGO_VITE["default"]["dev_mode"] in development and production templates - Add django‑vite dependency conditionally when use_vite is set in pyproject.toml and requirements - Create new vite.config.ts template with React, Tailwind, dev server proxy, and asset resolution - Enhancements - Align Tailwind and Django settings to respect Vite mode - Update dependency templates to reflect Vite usage - Bug Fixes - (none)
This commit is contained in:
6 files changed
+68
No files matched your search
@@ -225,3 +225,13 @@ TAILWIND_CLI_CONFIG = {
|
||||
},
|
||||
}
|
||||
# @ENDIF
|
||||
|
||||
# @IF use_vite
|
||||
# Vite Settings
|
||||
DJANGO_VITE = {
|
||||
"default": {
|
||||
"manifest_path": BASE_DIR / "static" / "dist" / "manifest.json",
|
||||
"static_url_prefix": "dist",
|
||||
}
|
||||
}
|
||||
# @ENDIF
|
||||
@@ -40,3 +40,8 @@ CORS_ALLOW_CREDENTIALS = True
|
||||
|
||||
# Disable HTTPS redirect in development
|
||||
SECURE_SSL_REDIRECT = False
|
||||
|
||||
# @IF use_vite
|
||||
# Vite Settings
|
||||
DJANGO_VITE["default"]["dev_mode"] = True
|
||||
# @ENDIF
|
||||
@@ -72,3 +72,8 @@ TAILWIND_CLI_VERSION = "4.1.3" # Pin version
|
||||
TAILWIND_CLI_AUTOMATIC_DOWNLOAD = False # Use pre-installed CLI
|
||||
TAILWIND_CLI_DIST_CSS = "static/css/tailwind.min.css"
|
||||
# @ENDIF
|
||||
|
||||
# @IF use_vite
|
||||
# Vite Settings
|
||||
DJANGO_VITE["default"]["dev_mode"] = False
|
||||
# @ENDIF
|
||||
@@ -26,6 +26,9 @@ dependencies = [
|
||||
# @IF use_htmx
|
||||
"django-htmx",
|
||||
# @ENDIF
|
||||
# @IF use_vite
|
||||
"django-vite",
|
||||
# @ENDIF
|
||||
# @IF use_database_url
|
||||
"dj-database-url",
|
||||
# @ENDIF
|
||||
|
||||
@@ -12,6 +12,7 @@ django-cors-headers
|
||||
whitenoise
|
||||
django-tailwind-cli # @IF use_tailwind
|
||||
django-htmx # @IF use_htmx
|
||||
django-vite # @IF use_vite
|
||||
# @IF database_type == 'mysql'
|
||||
mysqlclient
|
||||
# @ELSE
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { defineConfig } from "vite"
|
||||
import react from "@vitejs/plugin-react-swc"
|
||||
import tailwindcss from "@tailwindcss/vite"
|
||||
import path from "path"
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig(({ mode }) => ({
|
||||
plugins: [react(), tailwindcss()],
|
||||
base: mode === "production" ? "/static/" : "/",
|
||||
build: {
|
||||
outDir: "../[[ module_name ]]/static/dist",
|
||||
emptyOutDir: true,
|
||||
manifest: "manifest.json",
|
||||
rollupOptions: {
|
||||
input: "src/main.tsx",
|
||||
},
|
||||
},
|
||||
server: {
|
||||
port: 5173,
|
||||
host: "127.0.0.1",
|
||||
proxy: {
|
||||
"/api": {
|
||||
target: "http://localhost:8000",
|
||||
changeOrigin: true,
|
||||
},
|
||||
"/media": {
|
||||
target: "http://localhost:8000",
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": path.resolve(__dirname, "./src"),
|
||||
},
|
||||
dedupe: [
|
||||
"react",
|
||||
"react-dom",
|
||||
"react/jsx-runtime",
|
||||
"react/jsx-dev-runtime",
|
||||
"@tanstack/react-query",
|
||||
],
|
||||
},
|
||||
}))
|
||||
Reference in new issue
Block a user