Skip to content

Commit 84d08a3

Browse files
Migrate CSS to Tailwind utilities – Phase 2 (#89)
Issue #47 This PR continues the gradual migration from custom CSS to Tailwind. ### Changes **Build configuration** - Consolidated Tailwind CSS into Vite-managed build pipeline - Fixed double entrypoint: CSS was previously loaded via both Tailwind CLI (`application.tailwind.css`) and Vite (`application.css`), causing conflicts - Single entrypoint: `application.js` imports `application.css`, eliminating duplicate style loading - Removed standalone Tailwind CLI setup (`application.tailwind.css`) - Removed `@tailwindcss/cli` dependency (Vite handles Tailwind via `@tailwindcss/vite` plugin) - Removed `bin/tailwind-build` script (no longer needed) - Updated asset pipeline to use Vite for CSS bundling - Updated `Stylesheets` helper to exclude Vite-managed frontend directory and legacy Tailwind builds directory **CSS migrations** - Migrated `flash.css` to Tailwind utilities in `application.html.erb` - Migrated `.input--code` to Tailwind component class using `@apply` - Added Tailwind utility class definitions for existing text and spacing utilities (`txt-*`, `pad`, `margin-block`, `gap`) - Consolidated color system and design tokens into `application.css` theme **Template updates** - Replaced flash component classes with Tailwind utilities - Updated several templates to use standard Tailwind classes (`align-center` → `items-center`, `flex-column` → `flex-col`) **Documentation** - Updated `README.md` to use `bin/dev` and removed separate Tailwind watch instructions - Added migration status comments to `buttons.css` and `inputs.css` - Documented which classes remain in CSS due to complexity (nested selectors, pseudo-classes, CSS variables) ### What remains in CSS - Button classes (`.btn` and modifiers) - nested selectors, pseudo-classes, CSS variables - Input classes (`.input`, `.input--actor`, `.input--file`) - pseudo-classes, nested selectors - Switch classes (`.switch`, `.switch__input`, `.switch__btn`) - pseudo-elements These classes use features like nested selectors, `:focus-within`, `:has()`, `::before`/`::after` pseudo-elements, and CSS custom properties that require more careful migration. ### Next steps 1. Continue migrating component-specific CSS files (`buttons.css`, `inputs.css`) 2. Migrate complex component CSS (`messages.css`, `sidebar.css`, `stats.css`, `navigation.css`) 3. Remove migrated CSS files once all usages are replaced 4. Final goal: eliminate all custom CSS files in favor of Tailwind utilities --- AI disclaimer: This PR was implemented with AI assistance (Claude Sonnet 4.5, gpt-5-codex, gpt-5-high) for code generation. All code was self-reviewed and directed throughout the development process.
1 parent 578ad95 commit 84d08a3

File tree

19 files changed

+323
-1144
lines changed

19 files changed

+323
-1144
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ENV RAILS_ENV="production" \
1616
# Throw-away build stage to reduce size of final image
1717
FROM --platform=$TARGETPLATFORM base as build
1818

19-
# Install packages need to build gems and Node.js for Tailwind
19+
# Install packages need to build gems and Node.js for Vite
2020
RUN apt-get update -qq && \
2121
apt-get install -y build-essential git pkg-config nodejs npm
2222

@@ -27,9 +27,9 @@ RUN bundle install && \
2727

2828
COPY . .
2929

30-
# Install Node dependencies and build Tailwind CSS
30+
# Install Node dependencies and build assets with Vite
3131
RUN npm install && \
32-
npx @tailwindcss/cli -i app/assets/stylesheets/application.tailwind.css -o app/assets/builds/tailwind.css
32+
npm run build
3333

3434
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
3535
RUN mkdir -p /rails/storage/logs

Procfile.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22
vite: bin/vite dev
3-
web: bin/rails s
3+
web: PORT=3000 bin/rails s

README.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,15 @@ bin/setup
2828
Start the app in development:
2929

3030
```bash
31-
bin/rails server
31+
bin/dev
3232
```
3333

34-
`vite_rails` is configured with `autoBuild: true`, and the layout includes the Vite tags; assets are compiled and served automatically, so Inertia and Tailwind work without a separate Vite process.
34+
This starts both the Rails server and Vite dev server using Foreman (via Procfile.dev).
3535

36-
The `bin/setup` script installs Ruby gems and Node packages (via `npm install`), prepares the database, builds Tailwind CSS once, and configures the application.
36+
The `bin/setup` script installs Ruby gems and Node packages (via `npm install`), prepares the database, and configures the application.
3737
If you skip `bin/setup`, install frontend dependencies manually with `npm install`.
3838

39-
Tailwind in this app is used in two places:
40-
41-
- For Rails views (asset pipeline): if you edit files under `app/assets/stylesheets/**`, run:
42-
43-
```bash
44-
bin/tailwind-build --watch
45-
```
46-
47-
- For Inertia/React pages (Vite): styles under `app/frontend/**` are processed automatically by Vite through `vite_rails` during development — no separate Tailwind watch needed.
39+
All CSS is managed through Vite. Tailwind processes styles from `app/frontend/entrypoints/application.css`, which is automatically rebuilt during development.
4840

4941
## Running in production
5042

app/assets/stylesheets/application.tailwind.css

Lines changed: 0 additions & 335 deletions
This file was deleted.

app/assets/stylesheets/application/buttons.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/* PHASE 2 MIGRATION STATUS: Complex classes with nested selectors, CSS custom properties, and pseudo-classes */
2+
/* NOTE: Base button classes remain in CSS due to complexity (nested selectors, pseudo-classes, CSS variables) */
3+
/* Button modifier classes (.btn--reversed, .btn--negative, etc.) primarily set CSS variables */
4+
/* These work together with the base .btn class which handles the complex styling */
15
:root {
26
--btn-size: 2.65em;
37
/* Define a slightly smaller size for the navbar action buttons */

0 commit comments

Comments
 (0)