Skip to content

Commit 24f188a

Browse files
Merge pull request #40 from OneBusAway/vite-npm
Build webapp Tailwind via Vite instead of the in-browser Play CDN
2 parents 62ad55c + b1967d3 commit 24f188a

13 files changed

Lines changed: 3001 additions & 6 deletions

File tree

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Local Maven build outputs — re-generated inside the builder stage.
22
**/target/
33

4+
# Local npm installs — frontend-maven-plugin runs `npm ci` inside the
5+
# builder stage, so any host-side install would just bloat the build context.
6+
**/node_modules/
7+
48
# Per-deployment runtime config + logs + GTFS payload + Postgres bind data.
59
# Mounted into containers at runtime via volumes, not baked into the image.
610
.deploy/

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ __pycache__/
2424
.playwright-mcp/
2525
map-fixed.png
2626

27+
# Frontend npm installs (transitclockWebapp).
28+
node_modules/
29+
2730
# Top-level docker-stack secrets (DB password, API key). .env.example is
2831
# committed as a template; .env is per-deployment.
2932
/.env

CLAUDE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Built from the repository root as a Maven multi-module project.
2121

2222
There is no lint step configured in the build.
2323

24+
The webapp module has a frontend toolchain (Vite + Vitest) wired into Maven via `frontend-maven-plugin`. `mvn package` on `transitclockWebapp` automatically downloads a pinned Node, runs `npm ci`, and runs `vite build` — its output (`target/frontend-dist/`) is folded into the WAR at `/dist`. `mvn verify` also runs Vitest. `-DskipTests` skips Vitest (the Vite build still runs because the WAR depends on its output).
25+
2426
## Code coverage
2527

2628
JaCoCo 0.8.12 is wired at the root `pom.xml`. It inherits into any module that declares `<parent>`, which today means `transitclock`, `transitclockBarefootClient`, and `transitclockTraccarClient`. `transitclockApi` and `transitclockWebapp` don't declare `<parent>`, so they currently produce no coverage data.
@@ -83,6 +85,7 @@ GTFS data in the DB is versioned by `configRev` and travel-time data by `travelT
8385
- Bring tomcat up with the override: `docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d tomcat`. The override deletes `web.war` from the image at startup so it doesn't fight the bind mount.
8486
- The override only affects `tomcat`; `core`, `db`, and `tools` keep their normal behavior.
8587
- Java class changes (anything under `transitclockWebapp/src/main/java`, `transitclockApi`, or core) still require `mvn -pl transitclockWebapp -am package -DskipTests` followed by `docker compose -f docker-compose.yml -f docker-compose.dev.yml restart tomcat`. Only the JSP/CSS/JS/HTML/image loop is fast.
88+
- For Tailwind / Vite-bundled assets, run `cd transitclockWebapp && npm run dev` in a second terminal — Vite watches `frontend/` and writes to `target/frontend-dist/`, which the dev override bind-mounts into Tomcat at `/dist`. Browser refresh shows the change.
8689
- To return to the production-style baked-WAR flow, drop the `-f docker-compose.dev.yml` flag.
8790

8891
## Conventions to be aware of

docker-compose.dev.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
# no docker rebuild, no compose restart.
55
#
66
# Usage:
7-
# # one-time: populate target/web/WEB-INF/{lib,classes} for the JSPs
7+
# # one-time: populate target/web/WEB-INF/{lib,classes} for the JSPs and
8+
# # target/frontend-dist/ for the Vite-built Tailwind bundle.
89
# mvn -pl transitclockWebapp -am package -DskipTests
910
#
11+
# # for fast Tailwind / frontend iteration, run Vite in watch mode in a
12+
# # second terminal — output goes to target/frontend-dist/, which the
13+
# # bind mount below picks up:
14+
# cd transitclockWebapp && npm run dev
15+
#
1016
# # bring up tomcat with the override
1117
# docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d tomcat
1218
#
@@ -27,6 +33,7 @@ services:
2733
- ./transitclockWebapp/src/main/webapp:/usr/local/tomcat/webapps/web
2834
- ./transitclockWebapp/target/web/WEB-INF/lib:/usr/local/tomcat/webapps/web/WEB-INF/lib:ro
2935
- ./transitclockWebapp/target/web/WEB-INF/classes:/usr/local/tomcat/webapps/web/WEB-INF/classes:ro
36+
- ./transitclockWebapp/target/frontend-dist:/usr/local/tomcat/webapps/web/dist:ro
3037
command:
3138
- |
3239
if [ -z "${TRANSITCLOCK_APIKEY:-}" ]; then
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@import "tailwindcss";
2+
3+
@source "../src/main/webapp/**/*.jsp";
4+
@source "../src/main/webapp/**/*.tag";
5+
@source "../src/main/webapp/**/*.html";
6+
@source "../src/main/webapp/**/*.js";
7+
@source "../frontend/**/*.js";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function classNames(...parts) {
2+
return parts.filter(Boolean).join(' ');
3+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { classNames } from './utils.js';
3+
4+
describe('classNames', () => {
5+
it('joins truthy parts with spaces', () => {
6+
expect(classNames('a', 'b', 'c')).toBe('a b c');
7+
});
8+
9+
it('skips falsy parts', () => {
10+
expect(classNames('a', null, undefined, false, '', 'b')).toBe('a b');
11+
});
12+
});

0 commit comments

Comments
 (0)