Skip to content

Commit 32d5aeb

Browse files
fix: prevent Vite files conflict with Next.js frontend
- Add frontend == 'htmx-tailwind' condition to Vite template files - Update tests to check for Vite (default) and CDN modes separately - Add new test_htmx_frontend_cdn_mode test
1 parent afe8e4e commit 32d5aeb

7 files changed

+21
-1
lines changed

template/frontend/{% if frontend_bundling == 'vite' %}package.json{% endif %}.jinja renamed to template/frontend/{% if frontend == 'htmx-tailwind' and frontend_bundling == 'vite' %}package.json{% endif %}.jinja

File renamed without changes.

template/frontend/{% if frontend_bundling == 'vite' %}postcss.config.js{% endif %}.jinja renamed to template/frontend/{% if frontend == 'htmx-tailwind' and frontend_bundling == 'vite' %}postcss.config.js{% endif %}.jinja

File renamed without changes.

template/frontend/{% if frontend_bundling == 'vite' %}src{% endif %}/{% if frontend_bundling == 'vite' %}main.js{% endif %}.jinja renamed to template/frontend/{% if frontend == 'htmx-tailwind' and frontend_bundling == 'vite' %}src{% endif %}/{% if frontend == 'htmx-tailwind' and frontend_bundling == 'vite' %}main.js{% endif %}.jinja

File renamed without changes.

template/frontend/{% if frontend_bundling == 'vite' %}src{% endif %}/{% if frontend_bundling == 'vite' %}styles.css{% endif %}.jinja renamed to template/frontend/{% if frontend == 'htmx-tailwind' and frontend_bundling == 'vite' %}src{% endif %}/{% if frontend == 'htmx-tailwind' and frontend_bundling == 'vite' %}styles.css{% endif %}.jinja

File renamed without changes.

template/frontend/{% if frontend_bundling == 'vite' %}tailwind.config.js{% endif %}.jinja renamed to template/frontend/{% if frontend == 'htmx-tailwind' and frontend_bundling == 'vite' %}tailwind.config.js{% endif %}.jinja

File renamed without changes.

template/frontend/{% if frontend_bundling == 'vite' %}vite.config.js{% endif %}.jinja renamed to template/frontend/{% if frontend == 'htmx-tailwind' and frontend_bundling == 'vite' %}vite.config.js{% endif %}.jinja

File renamed without changes.

tests/test_generation.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,36 @@ def test_no_api_excludes_frameworks(generate):
204204

205205

206206
def test_htmx_frontend_templates_generated(generate):
207-
"""Test that HTMX frontend generates templates."""
207+
"""Test that HTMX frontend generates templates with Vite (default)."""
208208
project = generate(frontend="htmx-tailwind")
209209

210210
templates_dir = project / "templates"
211211
assert (templates_dir / "base.html").exists()
212212

213+
base_html = (templates_dir / "base.html").read_text()
214+
assert "{% block" in base_html
215+
# Vite is the default, so check for vite tags
216+
assert "django_vite" in base_html
217+
assert "vite_asset" in base_html
218+
219+
# Vite frontend files should exist
220+
frontend_dir = project / "frontend"
221+
assert (frontend_dir / "package.json").exists()
222+
assert (frontend_dir / "vite.config.js").exists()
223+
assert (frontend_dir / "tailwind.config.js").exists()
224+
225+
226+
def test_htmx_frontend_cdn_mode(generate):
227+
"""Test that HTMX frontend with CDN mode uses CDN links."""
228+
project = generate(frontend="htmx-tailwind", frontend_bundling="cdn")
229+
230+
templates_dir = project / "templates"
213231
base_html = (templates_dir / "base.html").read_text()
214232
assert "{% block" in base_html
215233
assert "tailwindcss" in base_html
216234
assert "htmx" in base_html
235+
# Should not have vite tags
236+
assert "django_vite" not in base_html
217237

218238

219239
def test_nextjs_frontend_generated(generate):

0 commit comments

Comments
 (0)