Rails + Inertia + React + ShadCN
Follow instructions here:
Note: You can remove these lines from the head since they won't be used:
Test it out by installing any shadcn component, like a button:
and add it to a page:
In addition to those instructions, I also had to make several other fixes to get it working:
Fix the @ issue by updating my vite.config.ts to this:
CSS styles not showing up
Here are the key changes that were necessary to make Tailwind styles work with shadcn/ui in your Rails + Inertia + Vite setup:
Required Changes
1. Import CSS in the Inertia entrypoint (app/javascript/entrypoints/inertia.ts)
app/javascript/entrypoints/inertia.ts)Added the CSS import so Vite processes and injects the Tailwind styles:
2. Configure Tailwind v4 to scan the correct directories (app/javascript/entrypoints/application.css)
app/javascript/entrypoints/application.css)Added @source directives to tell Tailwind where to find your component files:
This ensures Tailwind scans both app/frontend/ (where shadcn components live) and app/javascript/pages/ (where your Inertia pages live) to generate the necessary utility classes.
3. Update TypeScript configuration (tsconfig.app.json)
tsconfig.app.json)Changed the include array to cover both directories:
This allows TypeScript to resolve imports from the app/frontend directory where shadcn components are installed.
4. Remove duplicate CSS loading (app/views/layouts/application.html.erb)
app/views/layouts/application.html.erb)Removed this line:
Since the CSS is now imported in the JavaScript entrypoint, loading it separately was causing conflicts.
Summary
The core issue was that Tailwind v4 wasn't scanning the app/frontend directory where shadcn/ui installs its components, so the utility classes (like bg-primary, hover:bg-primary/90, etc.) weren't being generated. The @source directive fixed this.
Last updated