Installation
Setting up Tailwind CSS in a SolidJS project.
Start by creating a new SolidJS project if you don't have one set up already. The most common approach is to use the SolidJS Vite template.
npx degit solidjs/templates/js my-projectcd my-project
Install @tailwindcss/vite
and its peer dependencies via npm.
npm install tailwindcss @tailwindcss/vite
Add the @tailwindcss/vite
plugin to your Vite configuration.
import { defineConfig } from 'vite';import solidPlugin from 'vite-plugin-solid';import tailwindcss from '@tailwindcss/vite';export default defineConfig({ plugins: [ tailwindcss(), solidPlugin(), ], server: { port: 3000, }, build: { target: 'esnext', },});
Add an @import
to ./src/index.css
that imports Tailwind CSS.
@import "tailwindcss";
Run your build process with npm run dev
.
npm run dev
Start using Tailwind’s utility classes to style your content.
export default function App() { return ( <h1 class="text-3xl font-bold underline"> Hello world! </h1> )}