Starting fresh? Use shadcn/create to save time. It handles Tailwind, TypeScript, and path alias configuration for you, plus custom themes and presets.
The current version of Vite splits TypeScript configuration into three files, two of which need to be edited.
Add the
baseUrl and paths properties to the compilerOptions section of the tsconfig.json and
tsconfig.app.json files:{
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.node.json"
}
],
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}
import path from "path"
import tailwindcss from "@tailwindcss/vite"
import react from "@vitejs/plugin-react"
import { defineConfig } from "vite"
// https://vite.dev/config/
export default defineConfig({
plugins: [react(), tailwindcss()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
})
The command above will add the
Button component to your project. You can then import it like this: