This project uses Vite with React and TypeScript, along with three UI libraries: shadcn, Aceternity UI, and MagicUI. Follow the instructions below to set up and use each library.
- Create a new Vite project with React and TypeScript:
npm create vite@latest my-project -- --template react-ts
- Navigate to your project directory:
cd my-project
- Install dependencies:
npm install
- Run the development server:
npm run dev
- Build the project:
npm run build
- Preview the production build:
npm run preview
shadcn is a collection of re-usable components built using Radix UI and Tailwind CSS.
-
Install dependencies:
npm install -D tailwindcss postcss autoprefixer npx tailwindcss init -p
-
Initialize shadcn in your project:
npx shadcn-ui@latest init
-
Follow the prompts to configure your project. When asked about the framework, choose "Other".
-
Update your
vite.config.ts
:import path from "path"; import react from "@vitejs/plugin-react"; import { defineConfig } from "vite"; export default defineConfig({ plugins: [react()], resolve: { alias: { "@": path.resolve(__dirname, "./src"), }, }, });
To add a shadcn component:
npx shadcn-ui@latest add [component-name]
Replace [component-name]
with the desired component, e.g., button
, card
, etc.
import { Button } from "@/components/ui/button";
export default function App() {
return <Button>Click me</Button>;
}
Aceternity UI is not officially supported for Vite + React TypeScript projects. However, you can still use its components by copying the code and adapting it to your project.
- Visit the Aceternity UI website and find the component you want to use.
- Copy the component code and create a new file in your project (e.g.,
src/components/AceternityComponent.tsx
). - Adapt the component code to work with TypeScript and your project structure.
import AceternityComponent from "@/components/AceternityComponent";
export default function App() {
return <AceternityComponent />;
}
Similar to Aceternity UI, MagicUI doesn't have an official CLI for Vite projects. You'll need to manually add components.
- Visit the MagicUI website and find the component you want to use.
- Copy the component code and create a new file in your project (e.g.,
src/components/MagicComponent.tsx
). - Adapt the component code to work with TypeScript and your project structure.
- Update your
tailwind.config.js
with any required configurations for the component.
For a component like border-beam
, you might update your tailwind.config.js
like this:
/** @type {import('tailwindcss').Config} */
export default {
theme: {
extend: {
animation: {
"border-beam": "border-beam calc(var(--duration)*1s) infinite linear",
},
keyframes: {
"border-beam": {
"100%": {
"offset-distance": "100%",
},
},
},
},
},
};
To avoid conflicts between these libraries:
- Use CSS modules or a CSS-in-JS solution to scope styles.
- Prefix class names for each library.
- Use specific imports for each library to avoid naming conflicts.
- Create a custom theme that unifies the look across all libraries.
When adding new components from any of these libraries, make sure to:
- Check for naming conflicts with existing components.
- Test the new component with existing components to ensure compatibility.
- Update your custom theme if necessary to maintain visual consistency.
Remember to consult each library's documentation for detailed usage instructions and available components. For Aceternity UI and MagicUI, you may need to adapt the examples to work with Vite + React TypeScript.