Very simple Electron + Vue3 + Vite2 boilerplate

Very simple Electron + Vue3 + Vite2 boilerplate

electron-vue-vite

Very simple Electron + Vue3 + Vite2 boilerplate

πŸ₯³ Very simple Electron + Vue3 + Vite2 boilerplate.

Run Setup

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

# enter the project directory
cd electron-vue-vite

# install dependency
npm install

# develop
npm run dev

Directory

β”œ
β”œβ”€β”€ configs
β”œ   β”œβ”€β”€ vite-main.config.ts          Main-process config file, for -> src/main
β”œ   β”œβ”€β”€ vite-preload.config.ts       Preload-script config file, for -> src/preload
β”œ   β”œβ”€β”€ vite-renderer.config.ts      Renderer-script config file, for -> src/renderer
β”œ
β”œβ”€β”€ scripts
β”œ   β”œβ”€β”€ build.mjs                    Build script, for -> npm run build
β”œ   β”œβ”€β”€ electron-builder.config.mjs
β”œ   β”œβ”€β”€ watch.mjs                    Develop script, for -> npm run dev
β”œ
β”œβ”€β”€ src
β”œ   β”œβ”€β”€ main                         Main-process source code
β”œ   β”œβ”€β”€ preload                      Preload-script source code
β”œ   β”œβ”€β”€ renderer                     Renderer-process source code
β”œ

dist and src

  • Once npm run dev or npm run build is executed. Will be generated dist, it is the same as the src structure.

  • This ensures the accuracy of path calculation.

β”œβ”€β”€ dist
β”œ   β”œβ”€β”€ main
β”œ   β”œβ”€β”€ preload
β”œ   β”œβ”€β”€ renderer
β”œβ”€β”€ src
β”œ   β”œβ”€β”€ main
β”œ   β”œβ”€β”€ preload
β”œ   β”œβ”€β”€ renderer
β”œ

Communication

All NodeJs、Electron API invoke passed Preload-script

  • src/preload/index.ts

    // --------- Expose some API to Renderer process. ---------
    contextBridge.exposeInMainWorld('fs', fs)
    contextBridge.exposeInMainWorld('ipcRenderer', ipcRenderer)
  • src/renderer/src/main.ts

    console.log('fs', window.fs)
    console.log('ipcRenderer', window.ipcRenderer)

Mian window

Very simple Electron + Vue3 + Vite2 boilerplate

Wechat

Very simple Electron + Vue3 + Vite2 boilerplate

GitHub

View Github

Leave a Reply

Your email address will not be published.