Skip to content

inoss109/nuxt-electron

This branch is 69 commits behind caoxiemeihao/nuxt-electron:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

9cfb6bd Β· Feb 23, 2023

History

53 Commits
Feb 19, 2023
Feb 18, 2023
Dec 3, 2022
Dec 11, 2022
Feb 18, 2023
Nov 10, 2022
Feb 23, 2023
Dec 12, 2022
Feb 16, 2023
Feb 18, 2023
Feb 13, 2023
Dec 3, 2022
Dec 12, 2022
Dec 12, 2022
Feb 18, 2023

Repository files navigation

Nuxt Electron

npm version npm downloads License

Integrate Nuxt and Electron

Features

  • πŸš€ High-performance (Not Bundle, based on esbuild)
  • πŸ“¦ Out of the box
  • πŸ”₯ Hot restart

Quick Setup

  1. Add the following dependency to your project
# Using pnpm
pnpm add -D nuxt-electron vite-electron-plugin electron electron-builder

# Using yarn
yarn add --dev nuxt-electron vite-electron-plugin electron electron-builder

# Using npm
npm install --save-dev nuxt-electron vite-electron-plugin electron electron-builder
  1. Add nuxt-electron to the modules section of nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    'nuxt-electron',
  ],
})
  1. Create the electron/main.ts file and type the following code
import { app, BrowserWindow } from 'electron'

app.whenReady().then(() => {
  new BrowserWindow().loadURL(process.env.VITE_DEV_SERVER_URL)
})
  1. Add the main entry to package.json
{
+ "main": "dist-electron/main.js"
}

That's it! You can now use Electron in your Nuxt app ✨

Electron Options

This is based on the vite-electron-plugin, see the Documents for more detailed options

Here is the default electron options

export default defineNuxtConfig({
  modules: [
    'nuxt-electron',
  ],
  electron: {
    include: ['electron'],
    outDir: 'dist-electron',
  },
})

Recommend Structure

Let's use the official nuxt-starter-v3 template as an example

+ β”œβ”€β”¬ electron
+ β”‚ └── main.ts
  β”œβ”€β”¬ public
  β”‚ └── favicon.ico
  β”œβ”€β”€ .gitignore
  β”œβ”€β”€ .npmrc
  β”œβ”€β”€ index.html
  β”œβ”€β”€ app.vue
  β”œβ”€β”€ nuxt.config.ts
  β”œβ”€β”€ package.json
  β”œβ”€β”€ README.md
  └── tsconfig.json

Notes

By default, we force the App to run in SPA mode since we don't need SSR for desktop apps

About

Integrate Nuxt and Electron

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%