DEV Community

Cover image for How to add ShadCN to an electron-vite project.
Nedwize
Nedwize

Posted on

5 1

How to add ShadCN to an electron-vite project.

Currently, it's a bit tricky to add shadcn components to an electron-vite project, so I thought of creating a small write-up for anyone who gets stuck.

Add Tailwind

  • First of all we need to add TailwindCSS to support shadcn as the components are built on top on TailwindCSS.
  • At the time of writing this, TailwindCSS has released v4 and shadcn documentation tells you how to add TailwindCSS v3. But we will add the newer v4.
  • Run npm install tailwindcss @tailwindcss/vite
  • Add tailwindcss plugin to your electron.vite.config.ts file.
import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()]
  },
  preload: {
    plugins: [externalizeDepsPlugin()]
  },
  renderer: {
    resolve: {
      alias: {
        '@renderer': resolve('src/renderer/src')
      }
    },
    plugins: [react(), tailwindcss()]
  }
})
Enter fullscreen mode Exit fullscreen mode
  • Add this line @import "tailwindcss"; to the top of your /src/renderer/src/assets/main.css file.
  • Use a TailwindCSS classname somewhere in your project to verify if it works.
  • Run with npm run dev and verify.

Add ShadCN

  • Since we've already added TailwindCSS, we will directly jump to the point where we initialize ShadCN.
  • But first let's add these compiler options to tsconfig.node.json file.
{
  //...
  "compilerOptions": {
    "composite": true,
    "types": ["electron-vite/node"],
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/renderer/src/*"]
    },
    "moduleResolution": "bundler"
  }
}
Enter fullscreen mode Exit fullscreen mode
  • Now initialize ShadCN by running - npx shadcn@latest init
  • This will throw an error saying a supported framework is not found. So create a vite.config.ts file and paste the contents of electron.vite.config.ts inside it.
  • Add compiler options to tsconfig.json as well -
{
  //...
  "compilerOptions": {
    "composite": true,
    "types": ["electron-vite/node"],
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/renderer/src/*"]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode
  • Note: Move the lib/utils.ts directory to src/renderer/src/lib/utils.ts.
  • Run npx shadcn@latest init again and follow the flow, you should be able to get shadcn working now.

Fin.

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo 📊✨

Top comments (2)

Collapse
 
samloba profile image
samloba

Very helpfull post! thx

Collapse
 
ch1lam profile image
chilam

Thank you so much for this article!!! It helped me solve a problem I’ve been struggling with for a long time :)

Image of PulumiUP 2025

Transform Your Cloud Infrastructure

Join PulumiUP 2025 on May 6 for Expert Insights & Demos.

Register Now

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay