electron-sveltekit-template Svelte Themes

Electron Sveltekit Template

A modern starter template for building cross-platform desktop applications using Electron and SvelteKit with TypeScript support.

Electron + SvelteKit Template

A modern starter template for building cross-platform desktop applications using Electron and SvelteKit with TypeScript support.

image

Features

  • ⚔ Electron 37 + SvelteKit 2 integration
  • šŸ› ļø TypeScript support (via tsconfig.json)
  • šŸ“¦ Vite-powered build system (vite.config.ts)
  • šŸ”„ Hot-reload during development
  • šŸ–„ļø Cross-platform support (Windows, macOS, Linux)
  • šŸ›”ļø Preload script security (preload.cjs)
  • šŸ“ Organized project structure with separate main and renderer processes
  • šŸŽØ Global styling with app.css
  • šŸ”§ Development utilities in scripts/ folder

Prerequisites

  • Node.js 18+
  • npm 9+ or yarn 1.22+
  • Git

Installation

# Clone the repository
git clone https://github.com/chinni-03/electron-sveltekit-template.git
cd electron-sveltekit-template

Install dependencies

npm install

Start development server

npm run dev

Project Structure

electron-sveltekit-template/
ā”œā”€ā”€ electron            # Electron folder for main and preload files
|   ā”œā”€ā”€ main.js            # Electron main process entry
|   ā”œā”€ā”€ preload.cjs        # Preload script (CommonJS)
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ lib/           # Shared libraries and utilities
│   ā”œā”€ā”€ routes/        # SvelteKit routes and pages
│   ā”œā”€ā”€ app.css        # Global styles
│   ā”œā”€ā”€ app.d.ts       # TypeScript declarations
│   ā”œā”€ā”€ app.html       # Main HTML template
ā”œā”€ā”€ scripts/
│   └── dev-electron.js # Electron development script
ā”œā”€ā”€ static/            # Static assets (images, fonts, etc.)
ā”œā”€ā”€ .gitignore         # Git ignore rules
ā”œā”€ā”€ .npmrc             # npm configuration
ā”œā”€ā”€ package-lock.json  # Exact dependency tree
ā”œā”€ā”€ package.json       # Project metadata and scripts
ā”œā”€ā”€ README.md          # This file
ā”œā”€ā”€ svelte.config.js   # SvelteKit configuration
ā”œā”€ā”€ tsconfig.json      # TypeScript configuration
└── vite.config.ts     # Vite configuration

Available Scripts

Script Description
dev Start development server with HMR
build Build production-ready application
preview Preview production build locally
package Package application for current OS
make Create distributables for all platforms

Configuration Guide

Main Process

Edit main.js to configure:

  • Window settings
  • Native menus
  • Application lifecycle

Preload Script

Modify preload.cjs to:

  • Expose safe Node.js APIs
  • Set up IPC communication
  • Manage security policies

Build Configuration

Adjust vite.config.ts for:

  • Custom build options
  • Environment variables
  • Renderer process settings

Development Tips

  • Hot Reloading: Both renderer and main processes support hot reload during development
  • Debugging: Use Chrome DevTools for renderer process and VS Code for main process
  • Static Assets: Place images/fonts in static/ folder
  • Type Checking: Run tsc --noEmit to check types without compiling

Building for Production

# Build the application
npm run build

Troubleshooting

Issue: "Module not found" errors

Solution:
Delete node_modules and package-lock.json, then run:

npm install

Issue: Preload script not working

Solution:

  1. Ensure all exposed APIs are properly defined in preload.cjs
  2. Verify the preload script path in main.js is correct:
    // In main.js
    webPreferences: {
      preload: path.join(__dirname, 'preload.cjs')
    }
    
  3. Check for any TypeScript errors in the preload script
  4. Ensure the preload script is using CommonJS syntax (.cjs extension)

Contributing

We welcome contributions! Here's how to get started:

  1. Fork the repository
  2. Create a new branch:
    git checkout -b feature-branch
    
  3. Commit your changes:
    git commit -am 'Add new feature'
    
  4. Push to the branch:
    git push origin feature-branch
    
  5. Open a Pull Request with: - Description of changes - Screenshots if applicable - Reference to related issues

License

This project is licensed under the MIT License - see the LICENSE file for full details.

Support

For support, please:

  1. Open an issue on GitHub
  2. Include:
    • OS version
    • Node.js version
    • Steps to reproduce
    • Expected vs actual behavior
    • Screenshots if applicable

Built with ā¤ļø by chinni-03

Top categories

svelte logo

Need a Svelte website built?

Hire a professional Svelte developer today.
Loading Svelte Themes