-
-
Notifications
You must be signed in to change notification settings - Fork 26
feat(frontend): add Vite bundling option for HTMX+Tailwind #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ca32845
afe8e4e
32d5aeb
42803a0
43ef2f5
36f505c
4c71471
ac91dba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "name": "{{ project_slug }}-frontend", | ||
| "version": "0.1.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "vite", | ||
| "build": "vite build", | ||
| "preview": "vite preview" | ||
| }, | ||
| "dependencies": { | ||
| "htmx.org": "^1.9.10", | ||
| "alpinejs": "^3.13.3" | ||
| }, | ||
| "devDependencies": { | ||
| "autoprefixer": "^10.4.16", | ||
| "postcss": "^8.4.32", | ||
| "tailwindcss": "^3.4.0", | ||
| "vite": "^5.0.10" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export default { | ||
| plugins: { | ||
| tailwindcss: {}, | ||
| autoprefixer: {}, | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Import styles | ||
| import "./styles.css"; | ||
|
|
||
| // Import HTMX | ||
| import htmx from "htmx.org"; | ||
| window.htmx = htmx; | ||
|
|
||
| // Import Alpine.js | ||
| import Alpine from "alpinejs"; | ||
| window.Alpine = Alpine; | ||
| Alpine.start(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| @tailwind base; | ||
| @tailwind components; | ||
| @tailwind utilities; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /** @type {import('tailwindcss').Config} */ | ||
| export default { | ||
| content: [ | ||
| "../templates/**/*.html", | ||
| "./src/**/*.js", | ||
| ], | ||
| theme: { | ||
| extend: {}, | ||
| }, | ||
| plugins: [], | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { defineConfig } from "vite"; | ||
| import { resolve } from "path"; | ||
|
|
||
| export default defineConfig({ | ||
| base: "/static/", | ||
| build: { | ||
| manifest: "manifest.json", | ||
| outDir: resolve(__dirname, "../static/dist"), | ||
| rollupOptions: { | ||
| input: { | ||
| main: resolve(__dirname, "src/main.js"), | ||
| }, | ||
| }, | ||
| }, | ||
| server: { | ||
| host: "0.0.0.0", | ||
| port: 5173, | ||
| origin: "http://localhost:5173", | ||
| }, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -204,16 +204,48 @@ def test_no_api_excludes_frameworks(generate): | |
|
|
||
|
|
||
| def test_htmx_frontend_templates_generated(generate): | ||
| """Test that HTMX frontend generates templates.""" | ||
| """Test that HTMX frontend generates templates with Vite (default).""" | ||
| project = generate(frontend="htmx-tailwind") | ||
|
|
||
| templates_dir = project / "templates" | ||
| assert (templates_dir / "base.html").exists() | ||
|
|
||
| base_html = (templates_dir / "base.html").read_text() | ||
| assert "{% block" in base_html | ||
| # Vite is the default, so check for vite tags | ||
| assert "django_vite" in base_html | ||
| assert "vite_asset" in base_html | ||
|
|
||
| # Vite frontend files should exist | ||
| frontend_dir = project / "frontend" | ||
| assert (frontend_dir / "package.json").exists() | ||
| assert (frontend_dir / "vite.config.js").exists() | ||
| assert (frontend_dir / "tailwind.config.js").exists() | ||
|
|
||
| # Check Django settings include django_vite | ||
| settings = project / "config" / "settings" / "base.py" | ||
| settings_content = settings.read_text() | ||
| assert "django_vite" in settings_content | ||
| assert "DJANGO_VITE" in settings_content | ||
|
|
||
|
|
||
| def test_htmx_frontend_cdn_mode(generate): | ||
| """Test that HTMX frontend with CDN mode uses CDN links.""" | ||
| project = generate(frontend="htmx-tailwind", frontend_bundling="cdn") | ||
|
||
|
|
||
| templates_dir = project / "templates" | ||
| base_html = (templates_dir / "base.html").read_text() | ||
| assert "{% block" in base_html | ||
| assert "tailwindcss" in base_html | ||
| assert "htmx" in base_html | ||
| # Should not have vite tags | ||
| assert "django_vite" not in base_html | ||
|
Comment on lines
+232
to
+242
|
||
|
|
||
| # CDN mode should NOT create frontend build files | ||
| frontend_dir = project / "frontend" | ||
| assert not (frontend_dir / "package.json").exists() | ||
| assert not (frontend_dir / "vite.config.js").exists() | ||
| assert not (frontend_dir / "tailwind.config.js").exists() | ||
|
|
||
|
|
||
| def test_nextjs_frontend_generated(generate): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding assertions to verify that
django_viteis added toINSTALLED_APPSand thatDJANGO_VITEsettings are present in the generated settings file, similar to howtest_drf_api_generatedchecks for DRF configuration. This would provide more comprehensive coverage.Example additions: