creating a new React project using vite
npm create vite@latest
Add Tailwind and its configuration
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
Add the Tailwind directives to your CSS to index.css
file
@tailwind base;
@tailwind components;
@tailwind utilities;
jsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": [
"./src/*"
]
}
}
}
vite.config.js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
// <https://vitejs.dev/config/>
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
})
Run the shadcn-ui
init
command to setup your project
npx shadcn@latest init
answer Question
√ Which style would you like to use? » Default
√ Which color would you like to use as the base color? » Neutral
√ Would you like to use CSS variables for theming? ... no / yes
Install Components
npx shadcn@latest add button
tailwind.config.js
/** @type {import('tailwindcss').Config} */
export default {
darkMode: ["class"],
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {
borderRadius: {
lg: 'var(--radius)',
md: 'calc(var(--radius) - 2px)',
sm: 'calc(var(--radius) - 4px)'
},
colors: {}
}
},
plugins: [require("tailwindcss-animate")],
}
Example
import React from 'react'
import { Button } from "@/components/ui/button"
function App() {
return (
<div className='text-center'>
<h1 className='text-4xl mt-10 text-blue-400'>Hello</h1>
<Button>Click me</Button>
</div>
)
}
export default App