Single part at the root, COMPOSE_FILE in .env

This commit is contained in:
hh
2026-09-08 20:38:27 +02:00
parent ade2cebf63
commit ecd38ee28b
31 changed files with 70 additions and 28 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
# frontend-svelte
Copier template for a `frontend/` part: SvelteKit on Bun with Tailwind v4, ultracite (biome) and optional shadcn-svelte, served by a Bun server with SSR, as a static SPA behind `serve.ts`, or as a static SPA that the backend api serves from `frontend/build`.
Copier template for a SvelteKit frontend, either as a `frontend/` part next to other parts or alone at the root of the project (`layout`): SvelteKit on Bun with Tailwind v4, ultracite (biome) and optional shadcn-svelte, served by a Bun server with SSR, as a static SPA behind `serve.ts`, or as a static SPA that the backend api serves from `frontend/build`.
Ships `frontend/docker-compose.yml` with root-relative paths, `docker-compose.local.yml` (published ports) and `docker-compose.prod.yml` (the `caddy` network), a `Makefile` with `fmt`, `check`, `build` and `dev`, `.env.example`, `CLAUDE.md`, `.claude/rules` for Svelte and ultracite, the Svelte MCP server and `.impeccable/` scaffolding. Meant to be applied on top of the `infra` template.
Ships `frontend/docker-compose.yml` with root-relative paths, `docker-compose.local.yml` (published ports) and `docker-compose.prod.yml` (the `caddy` network), a `Makefile` with `fmt`, `check`, `build` and `dev`, `.env.example`, `CLAUDE.md`, `.claude/rules` for Svelte and ultracite, the Svelte MCP server and `.impeccable/` scaffolding. Applied on top of the `infra` template, `layout: parts` or `layout: single` respectively.
```sh
copier copy --trust -d project_name="My Thing" -d serve=bun <this-repo> <dest>
+19 -1
View File
@@ -13,6 +13,14 @@ project_slug:
help: Package name, snake_case
default: "{{ project_name | lower | replace(' ', '_') | replace('-', '_') | replace('.', '_') }}"
layout:
type: str
help: Where the frontend lives
choices:
In frontend/ next to other parts: part
At the root of the project: root
default: part
serve:
type: str
help: How the frontend is served
@@ -44,5 +52,15 @@ frontend_adapter:
when: false
default: "{{ 'bun' if serve == 'bun' else 'static' }}"
part_dir:
type: str
when: false
default: "{{ 'frontend' if layout == 'part' else '.' }}"
prefix:
type: str
when: false
default: "{{ 'frontend/' if layout == 'part' else '' }}"
_tasks:
- "{% if _copier_operation == 'copy' and install_deps %}sh -c 'cd frontend && bun install'{% else %}true{% endif %}"
- "{% if _copier_operation == 'copy' and install_deps %}sh -c 'cd {{ part_dir }} && bun install'{% else %}true{% endif %}"
@@ -4,7 +4,7 @@
{
"hooks": [
{
"command": "cd frontend && bun run fix --skip=correctness/noUnusedImports",
"command": "{% if layout == 'part' %}cd frontend && {% endif %}bun run fix --skip=correctness/noUnusedImports",
"type": "command"
}
],
-1
View File
@@ -1 +0,0 @@
PUBLIC_API_BASE_URL=/api
-17
View File
@@ -1,17 +0,0 @@
COMPOSE := docker compose --project-directory ..
.PHONY: fmt check build dev
fmt:
bun run fix
check:
bun run check
bun run lint
build:
{% if serve == 'api' %} $(COMPOSE) run --rm frontend-dev sh -c "bun install && bun run build"
{% else %} $(COMPOSE) build frontend
{% endif %}
dev:
bun run dev
@@ -0,0 +1,2 @@
{% if layout == 'root' %}COMPOSE_FILE=docker-compose.yml:docker-compose.local.yml
{% endif %}PUBLIC_API_BASE_URL=/api
+40
View File
@@ -0,0 +1,40 @@
COMPOSE := docker compose{% if layout == 'part' %} --project-directory ..{% endif %}
{% if layout == 'root' %}SERVICES := $(COMPOSE) --profile services
EXTERNAL := $(COMPOSE) --profile external
{% endif %}
.PHONY: {% if layout == 'root' %}env external recreate rebuild restart logs down {% endif %}fmt check build dev
fmt:
bun run fix
check:
bun run check
bun run lint
build:
{% if serve == 'api' %} $(COMPOSE) run --rm frontend-dev sh -c "bun install && bun run build"
{% else %} $(COMPOSE) build frontend
{% endif %}
dev:
bun run dev
{% if layout == 'root' %}
env:
@test -f .env || cp .env.example .env
external:
$(EXTERNAL) up -d
recreate: external
$(SERVICES) up -d --force-recreate
rebuild: build recreate
restart:
$(SERVICES) restart
logs:
$(SERVICES) logs -f --tail=100
down:
$(EXTERNAL) --profile services down
{% endif %}
@@ -1,15 +1,15 @@
services:
{% if serve != 'api' %} frontend:
build: frontend
build: {{ part_dir }}
image: {{ project_slug }}/frontend
profiles: [frontend, services]
restart: unless-stopped
env_file:
- path: .env
required: false
- path: frontend/.env
{% if layout == 'part' %} - path: frontend/.env
required: false
command: {% if serve == 'bun' %}[build/index.js]{% else %}[run, serve.ts]{% endif %}
{% endif %} command: {% if serve == 'bun' %}[build/index.js]{% else %}[run, serve.ts]{% endif %}
{% endif %} frontend-dev:
image: oven/bun:alpine
@@ -19,12 +19,12 @@ services:
env_file:
- path: .env
required: false
- path: frontend/.env
{% if layout == 'part' %} - path: frontend/.env
required: false
environment:
{% endif %} environment:
API_PROXY_TARGET: http://api:8080
volumes:
- ./frontend:/app
- {{ './frontend' if layout == 'part' else '.' }}:/app
- frontend_node_modules:/app/node_modules
- frontend_svelte_kit:/app/.svelte-kit
command: [sh, -c, "bun install && bun run dev --host 0.0.0.0 --port 3000"]