Skip to content

japhari/shadycn-react-starter-template

Repository files navigation

Vite + React + Tailwind Project Setup

Setup Steps

  1. First, run the create command:
npm create vite@latest
  1. You'll see these prompts:
npx
create-vite

│
◇ Project name:
│ vite-react-project
│
◇ Select a framework:
│ React
│
◇ Select a variant:
│ JavaScript
│
◇ Scaffolding project in
  1. Navigate to the project directory:
cd vite-react-project
  1. Install dependencies:
npm install
  1. Install Tailwind CSS and its Vite plugin:
npm install tailwindcss @tailwindcss/vite
  1. Configure the Vite plugin:

    • Add the @tailwindcss/vite plugin to your Vite configuration in vite.config.js:
    import { defineConfig } from "vite";
    import react from "@vitejs/plugin-react";
    import tailwind from "@tailwindcss/vite";
    
    export default defineConfig({
      plugins: [react(), tailwind()],
    });
  2. Import Tailwind CSS:

    • Add the following import to your main CSS file (src/index.css):
    @import "tailwindcss";
  3. Start the development server:

npm run dev
  1. Start using Tailwind:
    • Make sure your compiled CSS is included in the <head> of your HTML
    • Begin using Tailwind's utility classes in your components

The development server will start at http://localhost:5173/

Project Structure

vite-react-project/
├── public/
│   └── vite.svg
├── src/
│   ├── assets/
│   │   └── react.svg
│   ├── App.css
│   ├── App.jsx
│   ├── index.css
│   └── main.jsx
├── index.html
├── package.json
└── vite.config.js

Available Scripts

  • npm run dev - Starts the development server
  • npm run build - Builds the app for production
  • npm run preview - Locally preview the production build

Learn More

ShadCN Configuration

To integrate ShadCN components into this project, follow these steps:

  1. Install ShadCN CLI:

    npx shadcn@latest init
  2. Validate Configuration: Ensure that your tsconfig.json file includes the following alias:

    {
      "compilerOptions": {
        "baseUrl": "./",
        "paths": {
          "@/*": ["src/*"]
        }
      }
    }
  3. Update Vite Config: Add the alias configuration to vite.config.js:

    import { defineConfig } from "vite";
    import react from "@vitejs/plugin-react";
    import path from "path";
    
    export default defineConfig({
      plugins: [react()],
      resolve: {
        alias: {
          "@": path.resolve(__dirname, "./src"),
        },
      },
    });
  4. Start Using ShadCN Components: Import and use components like Button in your project:

    import { Button } from "@/components/ui/button";
    
    function Example() {
      return <Button variant='default'>Click Me</Button>;
    }
  5. Learn More: Visit the ShadCN Documentation for more details.

Try ShadCN Button Component

To add and use the ShadCN Button component in your project, follow these steps:

  1. Add the Button Component:

    Run the following command to add the Button component:

    npx shadcn@latest add button
  2. Use the Button Component in App.jsx:

    Update your App.jsx file to use the ShadCN Button component. Here’s an example:

    import { Button } from "@/components/ui/button";
    
    function App() {
      const [count, setCount] = useState(0);
    
      return (
        <div>
          <h1 className='text-3xl font-bold'>ShadCN Button Example</h1>
          <Button onClick={() => setCount((count) => count + 1)}>
            Count is {count}
          </Button>
        </div>
      );
    }
    
    export default App;
  3. Start the Development Server:

    Run the following command to start the development server and see the button in action:

    npm run dev

Workspace Structure

Here is a screenshot of the workspace structure:

Workspace Structure

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published