This repository serves as a template for quickly starting a new desktop application project using a modern tech stack:
@/*
, @shared/*
).Before you begin, ensure you have the following installed:
npm
.Create a New Repository from Template:
Clone Your New Repository:
git clone https://github.com/YOUR_USERNAME/YOUR_REPOSITORY_NAME.git
cd YOUR_REPOSITORY_NAME
Install the project dependencies using your preferred package manager:
npm install
# or
# yarn install
# or
# pnpm install
To start the development server and run the Electron application:
npm run dev
This command will:
Changes made to renderer code (React components, CSS) will often update live without a full restart. Changes to main process or preload scripts will usually require restarting the dev
command.
To build the application for distribution:
# Build for macOS (Intel + Apple Silicon Universal)
npm run build:mac
# Build for Windows
npm run build:win
# Build for Linux
npm run build:linux
# Build for all platforms defined in package.json
npm run build
The build process will:
electron-builder
to package the application into distributable formats (e.g., .dmg
, .zip
for macOS; .exe
for Windows; .AppImage
, .deb
for Linux).dist
directory.This template comes pre-configured with several key features:
tailwind.config.js
in the project root.src/renderer/src/assets/main.css
.@import "tailwindcss";
directive and CSS variables defined in main.css
.@theme inline { ... }
directive in main.css
to map CSS variables (from shadcn/ui setup) to Tailwind theme tokens (e.g., --color-foreground
maps to text-foreground
, bg-foreground
, etc.).tw-animate-css
.components.json
in the project root defines paths and theme settings for the CLI.npx shadcn@latest add <component_name>
# Example: npx shadcn@latest add button sheet dialog
This will add the component source code to src/renderer/src/components/ui/
.src/renderer/src/assets/main.css
.Aliases are configured for cleaner imports:
@/*
: Resolves to src/renderer/src/*
(Use in renderer code).@shared/*
: Resolves to src/shared/*
(Use for code shared between main/preload/renderer). Note: You might need to create the src/shared
directory.@main/*
: Resolves to src/main/*
(Use within main process code).@preload/*
: Resolves to src/preload/*
(Use within preload script code).Configuration Files:
tsconfig.web.json
(for TS) and electron.vite.config.ts
(for Vite bundling).tsconfig.node.json
(for TS).Example Usage:
// In a renderer component:
import { Button } from '@/components/ui/button'
import { cn } from '@/lib/utils'
import logo from '@/assets/logo.png'
// In main process (src/main/index.ts):
import { setupSomething } from '@shared/utils/setup'
import { createDbConnection } from '@main/db'
build/
: Contains resources for building (like icons).dist/
: Output directory for packaged applications.dist-electron/
: Intermediate build output used by electron-builder
.src/
: Source code.main/
: Electron main process code. Entry point: index.ts
.preload/
: Electron preload script(s). Entry point: index.ts
.renderer/
: React application code (UI).src/
: Main source for the React app.assets/
: CSS, images, fonts. main.css
is the key entry point here.components/
: React components (including ui/
for shadcn components).lib/
: Utility functions (like cn
from shadcn).App.tsx
: Root React component.main.tsx
: React application entry point.index.html
: HTML entry point for the renderer.shared/
(Optional): Create this for code shared between processes. Remember to update tsconfig.node.json
includes/paths if you use it.src/renderer/src/
. Start with App.tsx
. Add new shadcn components using the CLI.src/renderer/src/assets/main.css
. Edit tailwind.config.js
for broader theme changes (requires dev server restart).src/main/index.ts
or break logic into other files within src/main/
.src/preload/index.ts
to securely expose specific Node.js/Electron APIs to the renderer process via the contextBridge
.build/
directory with your own (icon.ico
, icon.icns
, icon.png
). Ensure electron-builder
config in package.json
or electron-builder.yml
points to them.appId
and productName
in the electron-builder
configuration.Happy Coding!