How to Use

Install and configure Cosmic UI for Vite.
Create project

Start by creating a new React project using vite. Select the React + TypeScript template:

pnpm
npm
yarn
bun
yarn create vite@latest
Add Tailwind CSS
pnpm
npm
yarn
bun
yarn add tailwindcss @tailwindcss/vite

Replace everything in src/index.css with the following:

src/index.css
Expand

@import "tailwindcss";
 
Expand
Edit tsconfig.json file

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:

tsconfig.json
Expand

{
  "files": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.node.json"
    }
  ],
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}
 
Expand
Edit tsconfig.app.json file

Add the following code to the tsconfig.app.json file to resolve paths, for your IDE:

tsconfig.app.json
Expand

{
  "compilerOptions": {
    // ...
    "baseUrl": ".",
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
    // ...
  }
}
 
Expand
Update vite.config.ts

Add the following code to the vite.config.ts so your app can resolve paths without error:

pnpm
npm
yarn
bun
yarn add -D @types/node
vite.config.ts
Expand

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"),
    },
  },
})
 
Expand
Add Components

You can now start adding components to your project.

src/App.tsx
Expand

import { Button } from "@/components/ui/button";

function App() {
  return (
    <div className="flex min-h-svh flex-col items-center justify-center">
      <Button variant="success">Button</Button>
    </div>
  )
}

export default App
 
Expand
Powered by synthetic caffeine · Deployed by Left4code · Signal traceable on GitHub.