DEV Community

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

Posted on

4 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.

Playwright CLI Flags Tutorial

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • 0:56 --last-failed: Zero in on just the tests that failed in your previous run
  • 2:34 --only-changed: Test only the spec files you've modified in git
  • 4:27 --repeat-each: Run tests multiple times to catch flaky behavior before it reaches production
  • 5:15 --forbid-only: Prevent accidental test.only commits from breaking your CI pipeline
  • 5:51 --ui --headed --workers 1: Debug visually with browser windows and sequential test execution

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Click on any timestamp above to jump directly to that section in the tutorial!

Watch Full Video 📹️

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 :)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

If this post resonated with you, feel free to hit ❤️ or leave a quick comment to share your thoughts!

Okay