diff --git a/src/djinit/templates/config/settings/base.py-tpl b/src/djinit/templates/config/settings/base.py-tpl index 15a5da0..29547fd 100644 --- a/src/djinit/templates/config/settings/base.py-tpl +++ b/src/djinit/templates/config/settings/base.py-tpl @@ -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 diff --git a/src/djinit/templates/config/settings/development.py-tpl b/src/djinit/templates/config/settings/development.py-tpl index 2e3c1b3..60a9e62 100644 --- a/src/djinit/templates/config/settings/development.py-tpl +++ b/src/djinit/templates/config/settings/development.py-tpl @@ -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 diff --git a/src/djinit/templates/config/settings/production.py-tpl b/src/djinit/templates/config/settings/production.py-tpl index c454e0f..40512a7 100644 --- a/src/djinit/templates/config/settings/production.py-tpl +++ b/src/djinit/templates/config/settings/production.py-tpl @@ -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 diff --git a/src/djinit/templates/project/pyproject.toml-tpl b/src/djinit/templates/project/pyproject.toml-tpl index 37e9a4f..532123a 100644 --- a/src/djinit/templates/project/pyproject.toml-tpl +++ b/src/djinit/templates/project/pyproject.toml-tpl @@ -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 diff --git a/src/djinit/templates/project/requirements-tpl b/src/djinit/templates/project/requirements-tpl index bfefe12..9dbb655 100644 --- a/src/djinit/templates/project/requirements-tpl +++ b/src/djinit/templates/project/requirements-tpl @@ -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 diff --git a/src/djinit/templates/project/vite.config.ts-tpl b/src/djinit/templates/project/vite.config.ts-tpl new file mode 100644 index 0000000..60f872b --- /dev/null +++ b/src/djinit/templates/project/vite.config.ts-tpl @@ -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", + ], + }, +}))