⚡️ Vite + SolidJS + Electron boilerplate.

Overview

vite-solid-electron

GitHub stars GitHub issues GitHub license Required Node.JS >= v14.17.0

Overview

  • Very simple Vite, SolidJS, Electron integration template.

  • Contains only the basic dependencies.

  • The extension is very flexible.

Installation

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

# open the project directory
cd vite-solid-electron

# install dependencies
npm install

# start the application
npm run dev

# make a production build
npm run build

Directory structure

Once dev or build npm-script is executed, the dist folder will be generated. It has the same structure as the packages folder, the purpose of this design is to ensure the correct path calculation.

├
├── build                     Resources for the production build
├   ├── icon.icns             Icon for the application on macOS
├   ├── icon.ico              Icon for the application
├   ├── installerIcon.ico     Icon for the application installer
├   ├── uninstallerIcon.ico   Icon for the application uninstaller
├
├── dist                      Generated after build according to the "packages" directory
├   ├── main
├   ├── preload
├   ├── renderer
├
├── release                   Generated after production build, contains executables
├   ├── {version}
├       ├── win-unpacked      Contains unpacked application executable
├       ├── Setup.exe         Installer for the application
├
├── scripts
├   ├── build.mjs             Develop script -> npm run build
├   ├── watch.mjs             Develop script -> npm run dev
├
├── packages
├   ├── main                  Main-process source code
├       ├── vite.config.ts
├   ├── preload               Preload-script source code
├       ├── vite.config.ts
├   ├── renderer              Renderer-process source code
├       ├── vite.config.ts
├

Use Electron and NodeJS API

🚧 By default, Electron doesn't support the use of API related to Electron and NodeJS in the Renderer process, but someone might need to use it. If so, you can see the template 👉 electron-vite-boilerplate

Invoke Electron and NodeJS API in Preload-script

  • packages/preload/index.ts

    import fs from "fs"
    import { contextBridge, ipcRenderer } from "electron"
    
    // --------- Expose some API to Renderer-process. ---------
    contextBridge.exposeInMainWorld("fs", fs)
    contextBridge.exposeInMainWorld("ipcRenderer", ipcRenderer)
  • packages/renderer/src/global.d.ts

    // Defined in the window
    interface Window {
      fs: typeof import("fs")
      ipcRenderer: import("electron").IpcRenderer
    }
  • packages/renderer/src/main.ts

    // Use Electron and NodeJS API in the Renderer-process
    console.log("fs", window.fs)
    console.log("ipcRenderer", window.ipcRenderer)

Use SerialPort, SQLite3, or other node-native addons in the Main-process

  • First, you need to make sure that the dependencies in the package.json are NOT in the "devDependencies". Because the project will need them after packaged.

  • Main-process, Preload-script are also built with Vite, and they're built as build.lib.
    So they just need to configure Rollup.

Click to see more 👉 packages/main/vite.config.ts

export default {
  build: {
    // built lib for Main-process, Preload-script
    lib: {
      entry: "index.ts",
      formats: ["cjs"],
      fileName: () => "[name].js",
    },
    rollupOptions: {
      // configuration here
      external: ["serialport", "sqlite3"],
    },
  },
}

dependencies vs devDependencies

  • First, you need to know if your dependencies are needed after the application is packaged.

  • Like serialport, sqlite3 they are node-native modules and should be placed in dependencies. In addition, Vite will not build them, but treat them as external modules.

  • Dependencies like Vue and SolidJS, which are pure javascript modules that can be built with Vite, can be placed in devDependencies. This reduces the size of the application.

Result

Special thanks

Special thanks to caoxiemeihao for almost the entire code base, i just modified a small part to make it work with SolidJS. Original code can be found here

You might also like...

🎉 基于 vite 2.0 + vue 3.0 + vue-router 4.0 + vuex 4.0 + element-plus 的后台管理系统vue3-element-admin

vue3-element-admin 🎉 基于 Vite 2.0 + Vue3.0 + Vue-Router 4.0 + Vuex 4.0 + element-plus 的后台管理系统 简介 vue3-element-admin 是一个后台前端解决方案,它基于 vue3 和 element-plu

Nov 28, 2022

Vite template with TypeScript, Chakra UI, Eslint Airbnb, Prettier

Vite + Typescript + ChakraUI = ❤️ This is a vite template that combines several technologies: Vite React TypeScript ChakraUI Eslint with eslint-config

Mar 26, 2022

Integrate Tauri in a Vite project to build cross-platform apps.

vite-plugin-tauri Integrate Tauri in a Vite project to build cross-platform apps Install Make sure to setup your environment for Tauri development. Th

Dec 15, 2022

A template repository / quick start to build Azure Static Web Apps with a Node.js function. It uses Vue.js v3, Vue Router, Vuex, and Vite.js.

A template repository / quick start to build Azure Static Web Apps with a Node.js function. It uses Vue.js v3, Vue Router, Vuex, and Vite.js.

Azure Static Web App Template with Node.js API This is a template repository for creating Azure Static Web Apps that comes pre-configured with: Vue.js

Jun 25, 2022

Using Cypress with Vite, React, TypeScript, MSW and react-query

Vie + Cypress + MSW + react-query Demo Example of using Cypress with Vite, MSW and react-query. Uses the appReady pattern to signal to Cypress when th

Jul 16, 2022

Some compile-time magic for your Vite project

💛 You can help the author become a full-time open-source maintainer by sponsoring him on GitHub. vite-plugin-compile-time Use this plugin to generate

Dec 15, 2022

vite+vue3.2+setup+elementPlus+eslint+js+stylelint

前期准备工作,npm包和vscode配置 !!!很重要,关乎整个Vue3开发阶段的代码提示 Volar使用 使用Vue3开发需要禁用vscode插件Vetur 然后安装 Volar(Vue Language Features),这样Vue3代码提示即使是使用js开发也非常友好 如果volar没有任何

Feb 8, 2022

vue3 + vite + typescript template

Vue 3 + Typescript + Vite This template should help get you started developing with Vue 3 and Typescript in Vite. The template uses Vue 3 script setu

Aug 1, 2022

Minimal setup for a WebXR project using Vite, Babylon.js, TypeScript, and Vue

Minimal setup for a WebXR project using Vite, Babylon.js, TypeScript, and Vue

WebXR-Vite-Babylon-Simple Minimal setup for WebXR development using: vite typescript vue 3 babylonjs 5 (ES6) Intentionally made minimal changes from t

Nov 13, 2022
Comments
  • App breaks with electron 22

    App breaks with electron 22

    Hi,

    Thanks for this template, it worked fine when I directly npm install and npm dev, but when I tried to update electron or Vite, it is breaking. Is there any documentation/tutorial anywhere explaining this setup? If you find some time and update the packages and provide some explanation of what each piece is doing, it would be awesome.

    Thanks, B.

    opened by bnbabu55 0
Owner
Christian Hansen
👨‍💻 Software developer with a passion for creating highly performant applications.
Christian Hansen
Chrome Extension Boilerplate with SolidJS + Vite + TypeScript + Manifest V3 + Hot Relaod

Chrome Extension Boilerplate with SolidJS + Vite + TypeScript + Manifest V3 + Hot Relaod Intro This boilerplate is made for creating chrome extensions

fuyutarow 34 Dec 27, 2022
Chrome Extension boilerplate with SolidJS + Vite + CRXJS

SolidJS Chrome Extension boilerplate An easy way to create Chrome extensions with SolidJS using Vite + CRXJS. Features For more functionality, check o

Ryan Conceicao 8 Dec 25, 2022
⏳ vue3 + electron + ts + vite = mini template

v3-electron ?? Electron16 + Vue3 + Vite2 运行项目 # enter the project directory cd v3-electron # install dependency yarn # develop yarn dev # build exe

UNPany 8 Nov 11, 2022
Integrate Vite and Electron

vite-plugin-electron Integrate Vite and Electron Example ?? vite-plugin-electron-quick-start Usage vite.config.ts import electron from 'vite-plugin-el

null 217 Jan 2, 2023
Vite-plugin-web-extension - A vite plugin for generating cross browser platform, ES module based web extensions.

vite-plugin-web-extension A vite plugin for generating cross browser platform, ES module based web extensions. Features Manifest V2 & V3 Support Compl

Ruben Medina 81 Dec 31, 2022
Vue 3 + Vite + SSR template based on Vite Plugin SSR and inspired by Vitesse

Vite Vue SSR Starter Vue 3 + Vite + SSR template based on Vite Plugin SSR and inspired by Vitesse Features ⚡️ Vue 3, Vite 2, TypeScript ?? Domain-Driv

Oleg Koval 10 Aug 2, 2022
Fastify boilerplate with Vite & Vitest

Fastify boilerplate with Vite & Vitest Enhance your Fastify DX with the power of Vite & Vitest. Features ⚡ All the power of Vite (Next Generation Fron

Emmanuel Salomon 31 Dec 13, 2022
Modern ThreeJS boilerplate powered by Vite & Typescript

Modern ThreeJS ⚡️ Modern ThreeJS boilerplate powered by Vite & Typescript. Features Powered with Vite ?? GUI controls using Tweakpane ?? Typescript ??

Alvaro Saburido 64 Jan 4, 2023
A client for QQ and more.:electron:

Icalingua++ Icalingua++ 是 Icalingua 的分支,為已經刪除的 Icalingua 提供有限的更新,同時歡迎社區提交PR。 Icalingua 这个名字是日语中「光」和拉丁语中「语言」的组合。 本项目希望为 Linux 打造一个会话前端框架,通过实现 Adapter 后

Icalingua++ 2.6k Dec 31, 2022
A Marko plugin for Vite

@marko/vite A Marko plugin for Vite. Installation npm install @marko/vite Example config import { defineConfig } from "vite"; import marko from "@mark

Marko 49 Nov 26, 2022