Nuxt 4 module for seamless Electron integration with Electron Forge.
- β¨ Zero Config - Works out of the box with sensible defaults
- π Auto Start - Automatically launches Electron in development mode
- π Hot Reload - Full HMR support for your Nuxt app
- π¦ Easy Packaging - Built-in Electron Forge integration
- π― Type Safe - Full TypeScript support
- β‘ Nuxt 4 Ready - Built for the latest Nuxt
The easiest way to get started is using the init command:
# Using npx (no installation required)
npx @atmoner/nuxt-electron init
# Or if you have the package installed
npm exec nuxt-electron-initThis will automatically:
- β Check if Nuxt is installed
- β
Install Nuxt automatically if not present (runs
npm create nuxt@latest new-nuxt-electron) - β
Create
main.js(Electron main process) - β
Create
forge.config.cjs(Electron Forge configuration) - β
Create
scripts/dev-electron.js(Development script) - β
Update your
package.jsonwith required scripts and dependencies - β
Add the module to your
nuxt.config.ts - β Install all required dependencies
Then just run:
npm run electron:devThat's it! Your Nuxt + Electron app is ready β¨
Note: If Nuxt was not installed, the init command will create it in a
new-nuxt-electrondirectory. You'll need to runcd new-nuxt-electronbefore running the dev command.
- Add
@atmoner/nuxt-electrondependency to your project
# Using npm
npm install --save-dev @atmoner/nuxt-electron
# Using yarn
yarn add --dev @atmoner/nuxt-electron
# Using pnpm
pnpm add -D @atmoner/nuxt-electron- Add
@atmoner/nuxt-electronto themodulessection ofnuxt.config.ts
export default defineNuxtConfig({
modules: ["@atmoner/nuxt-electron"],
electron: {
// Module options
},
})- Install Electron dependencies
npm install --save-dev electron @electron-forge/cli @electron-forge/maker-squirrel @electron-forge/maker-zip @electron-forge/maker-deb @electron-forge/maker-rpm @electron-forge/plugin-fuses @electron/fuses- Create required files (or copy from
templates/directory):main.js- Electron main processforge.config.cjs- Electron Forge configurationscripts/dev-electron.js- Development script
# If you used the automatic setup
npm run electron:dev
# Or manually
npm run devThis will start both the Nuxt dev server and Electron automatically.
# Build for production
npm run electron:build
# Or step by step
npm run build
npx electron-forge makeexport default defineNuxtConfig({
electron: {
// Enable/disable the module
enabled: true,
// Electron main file
main: "main.js",
// Forge config file
forgeConfig: "forge.config.js",
// Nuxt dev server port
port: 3000,
// Auto-start Electron in dev mode
autoStart: true,
// Delay before starting Electron (ms)
startDelay: 5000,
// Kill existing processes on start
killExisting: true,
},
})The module provides default templates for:
main.js- Electron main processforge.config.js- Electron Forge configuration
You can find these in the templates/ directory.
your-project/
βββ app/
β βββ app.vue
βββ public/
βββ modules/
β βββ nuxt-electron/ # If developing locally
βββ main.js # Electron main process
βββ forge.config.js # Electron Forge config
βββ nuxt.config.ts
βββ package.json
After running npx @atmoner/nuxt-electron init, your package.json will include:
{
"type": "module",
"scripts": {
"dev": "nuxt dev",
"build": "nuxt build",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"electron:dev": "node scripts/dev-electron.js",
"electron:build": "nuxt build && electron-forge make"
}
}- Development Mode: The module hooks into Nuxt's dev server lifecycle
- Auto Launch: When Nuxt is ready, Electron starts automatically
- Clean Exit: Processes are properly cleaned up on exit
- Production Build: Nuxt builds to
.output/, Electron Forge packages the app
Check out the playground/ directory for a complete example.
You can customize the Electron window in your main.js:
const mainWindow = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
},
})Configure different installers in forge.config.js:
export const makers = [
{
name: "@electron-forge/maker-squirrel",
platforms: ["win32"],
},
{
name: "@electron-forge/maker-zip",
platforms: ["darwin"],
},
{
name: "@electron-forge/maker-deb",
platforms: ["linux"],
},
]If you see "Port 24678 is already in use":
- The module automatically kills existing processes when
killExisting: true - Manually kill processes:
pkill -f "nuxt dev"
- Check that
main.jsexists in your project root - Ensure Electron dependencies are installed
- Try increasing
startDelayin module options
- Run
nuxt buildfirst beforeelectron-forge make - Check that
.output/directory exists - Verify
forge.config.jsincludes.outputinextraResource
# Install dependencies
npm install
# Generate type stubs
npm run dev:prepare
# Develop with the playground
npm run dev
# Build the module
npm run prepack
# Run tests
npm testContributions are welcome! Please feel free to submit a Pull Request.
