Convert Figma logo to code with AI

electron-vite logoelectron-vite-vue

🥳 Really simple Electron + Vite + Vue boilerplate.

4,152
541
4,152
30

Top Related Projects

A Foundation for Scalable Cross-Platform Apps

Clone to try a simple Electron app

Secure boilerplate for Electron app based on Vite. TypeScript + Vue/React/Angular/Svelte/Vanilla

Easily Build Your Vue.js App For Desktop With Electron

An Electron & Vue.js quick start boilerplate with vue-cli scaffolding, common Vue plugins, electron-packager/electron-builder, unit/e2e testing, vue-devtools, and webpack.

6,407

:electron: A complete tool for building and publishing Electron applications

Quick Overview

Electron-vite-vue is a template for building Electron applications using Vue 3 and Vite. It provides a modern, fast development environment for creating cross-platform desktop applications with web technologies, combining the power of Electron, Vue.js, and Vite's rapid build tool.

Pros

  • Fast development and hot-reloading thanks to Vite's build system
  • Easy-to-use template for quickly starting Electron projects with Vue 3
  • Includes TypeScript support out of the box
  • Provides a well-structured project setup with clear separation of main and renderer processes

Cons

  • May have a steeper learning curve for developers new to Electron or Vue
  • Limited customization options compared to building an Electron app from scratch
  • Potential compatibility issues with some Electron or Vue plugins not designed for this specific setup
  • Requires keeping up with updates for multiple technologies (Electron, Vue, Vite)

Code Examples

  1. Main process entry point (main/index.ts):
import { app, BrowserWindow } from 'electron'
import path from 'path'

app.whenReady().then(() => {
  const win = new BrowserWindow({
    webPreferences: {
      preload: path.join(__dirname, 'preload.js')
    }
  })

  if (process.env.VITE_DEV_SERVER_URL) {
    win.loadURL(process.env.VITE_DEV_SERVER_URL)
  } else {
    win.loadFile('dist/index.html')
  }
})
  1. Vue component example (src/components/HelloWorld.vue):
<script setup lang="ts">
import { ref } from 'vue'

const count = ref(0)
</script>

<template>
  <h1>{{ msg }}</h1>
  <button @click="count++">Count is: {{ count }}</button>
</template>
  1. Preload script example (preload/index.ts):
import { contextBridge, ipcRenderer } from 'electron'

contextBridge.exposeInMainWorld('electronAPI', {
  sendMessage: (message: string) => ipcRenderer.send('message', message),
  onResponse: (callback: (response: string) => void) => 
    ipcRenderer.on('response', (_event, response) => callback(response))
})

Getting Started

  1. Clone the repository:

    git clone https://github.com/electron-vite/electron-vite-vue.git
    cd electron-vite-vue
    
  2. Install dependencies:

    npm install
    
  3. Start the development server:

    npm run dev
    
  4. To build for production:

    npm run build
    

This will create a ready-to-distribute Electron application in the dist folder.

Competitor Comparisons

A Foundation for Scalable Cross-Platform Apps

Pros of electron-react-boilerplate

  • More mature and established project with a larger community
  • Extensive documentation and examples for various use cases
  • Includes pre-configured testing setup with Jest and React Testing Library

Cons of electron-react-boilerplate

  • Heavier initial setup with more dependencies
  • Slower build times compared to Vite-based solutions
  • Less flexible configuration options for advanced users

Code Comparison

electron-react-boilerplate:

import { app, BrowserWindow, shell, ipcMain } from 'electron';
import { autoUpdater } from 'electron-updater';
import log from 'electron-log';
import MenuBuilder from './menu';
import { resolveHtmlPath } from './util';

electron-vite-vue:

import { app, BrowserWindow, shell } from 'electron'
import { release } from 'node:os'
import { join } from 'node:path'
import { update } from './update'

The electron-react-boilerplate code snippet shows a more comprehensive import structure, including additional modules like ipcMain and custom utilities. The electron-vite-vue example is more concise, focusing on core Electron modules and Node.js built-ins.

Both projects offer solid foundations for Electron development, with electron-react-boilerplate providing a more feature-rich starting point, while electron-vite-vue offers a lighter, faster alternative with modern build tools. The choice between them depends on specific project requirements and developer preferences.

Clone to try a simple Electron app

Pros of electron-quick-start

  • Simpler setup, ideal for beginners or small projects
  • Minimal dependencies, easier to understand and maintain
  • Faster initial project creation and setup time

Cons of electron-quick-start

  • Limited build tooling and optimization features
  • Lacks modern development features like Hot Module Replacement (HMR)
  • No built-in support for TypeScript or other advanced JavaScript features

Code Comparison

electron-quick-start:

const { app, BrowserWindow } = require('electron')

function createWindow () {
  const win = new BrowserWindow({ width: 800, height: 600 })
  win.loadFile('index.html')
}

app.whenReady().then(createWindow)

electron-vite-vue:

import { app, BrowserWindow } from 'electron'
import path from 'path'

function createWindow() {
  const win = new BrowserWindow({ width: 800, height: 600 })
  win.loadURL(process.env.VITE_DEV_SERVER_URL)
}

app.whenReady().then(createWindow)

The main differences in the code are:

  1. electron-vite-vue uses ES6 import syntax
  2. electron-vite-vue loads the app from a Vite dev server URL
  3. electron-quick-start uses a simpler file loading approach

Overall, electron-quick-start is better for simple projects or learning, while electron-vite-vue offers more advanced features and better development experience for larger projects.

Secure boilerplate for Electron app based on Vite. TypeScript + Vue/React/Angular/Svelte/Vanilla

Pros of vite-electron-builder

  • Includes a more comprehensive build and packaging setup using electron-builder
  • Offers TypeScript support out of the box
  • Provides a more structured project layout with separate directories for main and renderer processes

Cons of vite-electron-builder

  • May have a steeper learning curve due to its more complex setup
  • Potentially slower build times compared to the simpler electron-vite-vue setup
  • Less frequently updated, which might lead to outdated dependencies

Code Comparison

vite-electron-builder:

import { app, BrowserWindow } from 'electron'
import path from 'path'

const createWindow = () => {
  const win = new BrowserWindow({
    webPreferences: {
      preload: path.join(__dirname, 'preload.js'),
    },
  })
}

electron-vite-vue:

import { app, BrowserWindow } from 'electron'
import path from 'path'

const createWindow = () => {
  const win = new BrowserWindow({
    webPreferences: {
      preload: path.join(__dirname, '../preload/index.js'),
    },
  })
}

The main difference in the code snippets is the path to the preload script, reflecting the different project structures. vite-electron-builder uses TypeScript, while electron-vite-vue uses JavaScript by default.

Both repositories provide solid foundations for Electron development with Vite, but vite-electron-builder offers a more feature-rich setup at the cost of increased complexity, while electron-vite-vue focuses on simplicity and ease of use.

Easily Build Your Vue.js App For Desktop With Electron

Pros of vue-cli-plugin-electron-builder

  • Seamless integration with Vue CLI, providing a familiar development environment for Vue developers
  • Extensive documentation and community support due to its longer presence in the ecosystem
  • Built-in support for TypeScript and various testing frameworks

Cons of vue-cli-plugin-electron-builder

  • Slower build times compared to electron-vite-vue, especially for larger projects
  • Relies on webpack, which can be more complex to configure and optimize
  • May have limitations when working with newer Vue 3 features and Composition API

Code Comparison

vue-cli-plugin-electron-builder:

module.exports = {
  pluginOptions: {
    electronBuilder: {
      builderOptions: {
        // Configure electron-builder options here
      }
    }
  }
}

electron-vite-vue:

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import electron from 'vite-plugin-electron'

export default defineConfig({
  plugins: [vue(), electron()]
})

The code comparison shows that electron-vite-vue uses Vite's configuration system, which is more concise and easier to understand. vue-cli-plugin-electron-builder, on the other hand, relies on Vue CLI's configuration structure, which may be more familiar to existing Vue developers but can be more verbose.

Both projects aim to simplify Electron development with Vue, but electron-vite-vue leverages the speed and simplicity of Vite, while vue-cli-plugin-electron-builder builds upon the established Vue CLI ecosystem.

An Electron & Vue.js quick start boilerplate with vue-cli scaffolding, common Vue plugins, electron-packager/electron-builder, unit/e2e testing, vue-devtools, and webpack.

Pros of electron-vue

  • Established project with a longer history and larger community
  • Comprehensive boilerplate with more built-in features
  • Includes a detailed user guide and documentation

Cons of electron-vue

  • Uses older versions of Vue and Electron
  • Less frequent updates and maintenance
  • Heavier initial setup with more dependencies

Code Comparison

electron-vue:

import Vue from 'vue'
import axios from 'axios'

import App from './App'
import router from './router'
import store from './store'

Vue.http = Vue.prototype.$http = axios

electron-vite-vue:

import { createApp } from 'vue'
import App from './App.vue'
import './samples/node-api'

createApp(App)
  .mount('#app')
  .$nextTick(() => {
    postMessage({ payload: 'removeLoading' }, '*')
  })

The code comparison shows that electron-vue uses Vue 2 syntax with a more traditional setup, while electron-vite-vue uses Vue 3 composition API and a more modern, streamlined approach. electron-vite-vue's setup is simpler and more focused on the core functionality, while electron-vue includes additional features like router and store setup out of the box.

6,407

:electron: A complete tool for building and publishing Electron applications

Pros of Electron Forge

  • More mature and widely adopted in the Electron ecosystem
  • Offers a comprehensive set of tools for packaging, publishing, and automating Electron app development
  • Provides better integration with native Node.js modules

Cons of Electron Forge

  • Steeper learning curve for developers new to Electron
  • Less flexibility in build configuration compared to Vite-based solutions
  • Slower build times, especially for larger projects

Code Comparison

Electron Forge (package.json):

{
  "scripts": {
    "start": "electron-forge start",
    "package": "electron-forge package",
    "make": "electron-forge make"
  }
}

Electron Vite Vue (package.json):

{
  "scripts": {
    "dev": "vite",
    "build": "vue-tsc --noEmit && vite build && electron-builder",
    "preview": "vite preview"
  }
}

The code comparison shows that Electron Forge uses its own CLI commands for starting, packaging, and building the app, while Electron Vite Vue leverages Vite's development server and build process, integrating with Electron Builder for packaging.

Electron Forge provides a more standardized approach to Electron development, while Electron Vite Vue offers the benefits of Vite's fast build times and hot module replacement, along with Vue.js integration for rapid UI development.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

electron-vite-vue

🥳 Really simple Electron + Vue + Vite boilerplate.

GitHub Build GitHub Discord

Features

📦 Out of the box
🎯 Based on the official template-vue-ts, less invasive
🌱 Extensible, really simple directory structure
💪 Support using Node.js API in Electron-Renderer
🔩 Support C/C++ native addons
🖥 It's easy to implement multiple windows

Quick Setup

# clone the project
git clone https://github.com/electron-vite/electron-vite-vue.git

# enter the project directory
cd electron-vite-vue

# install dependency
npm install

# develop
npm run dev

Debug

electron-vite-react-debug.gif

Directory

+ ├─┬ electron
+ │ ├─┬ main
+ │ │ └── index.ts    entry of Electron-Main
+ │ └─┬ preload
+ │   └── index.ts    entry of Preload-Scripts
  ├─┬ src
  │ └── main.ts       entry of Electron-Renderer
  ├── index.html
  ├── package.json
  └── vite.config.ts

FAQ