Compare commits

..

No commits in common. "690c58d20bb5b3416323f7bb18a00016b0722cd1" and "516234dce53bb92f35aea512e248d6f5d337b4b6" have entirely different histories.

7 changed files with 32 additions and 57 deletions

View File

@ -19,22 +19,16 @@
🔩 Support C/C++ native addons
🖥 It's easy to implement multiple windows
## Quick Setup
## Quick Start
```sh
# 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
npm create electron-vite
```
<!-- [![quick-start](https://asciinema.org/a/483731.svg)](https://asciinema.org/a/483731) -->
![electron-vite-vue.gif](/electron-vite-vue.gif)
## Debug
![electron-vite-react-debug.gif](https://github.com/electron-vite/electron-vite-react/blob/main/electron-vite-react-debug.gif?raw=true)

View File

@ -5,19 +5,18 @@
"$schema": "https://raw.githubusercontent.com/electron-userland/electron-builder/master/packages/app-builder-lib/scheme.json",
"appId": "YourAppID",
"asar": true,
"productName": "YourAppName",
"directories": {
"output": "release/${version}"
},
"files": [
"dist",
"dist-electron"
"dist-electron",
"dist"
],
"mac": {
"artifactName": "${productName}_${version}.${ext}",
"target": [
"dmg"
],
"artifactName": "${productName}-Mac-${version}-Installer.${ext}"
]
},
"win": {
"target": [
@ -28,18 +27,12 @@
]
}
],
"artifactName": "${productName}-Windows-${version}-Setup.${ext}"
"artifactName": "${productName}_${version}.${ext}"
},
"nsis": {
"oneClick": false,
"perMachine": false,
"allowToChangeInstallationDirectory": true,
"deleteAppDataOnUninstall": false
},
"linux": {
"target": [
"AppImage"
],
"artifactName": "${productName}-Linux-${version}.${ext}"
}
}

View File

@ -6,6 +6,6 @@ declare namespace NodeJS {
DIST_ELECTRON: string
DIST: string
/** /dist/ or /public/ */
VITE_PUBLIC: string
PUBLIC: string
}
}

View File

@ -14,7 +14,7 @@ import { join } from 'node:path'
//
process.env.DIST_ELECTRON = join(__dirname, '..')
process.env.DIST = join(process.env.DIST_ELECTRON, '../dist')
process.env.VITE_PUBLIC = process.env.VITE_DEV_SERVER_URL
process.env.PUBLIC = process.env.VITE_DEV_SERVER_URL
? join(process.env.DIST_ELECTRON, '../public')
: process.env.DIST
@ -43,7 +43,7 @@ const indexHtml = join(process.env.DIST, 'index.html')
async function createWindow() {
win = new BrowserWindow({
title: 'Main window',
icon: join(process.env.VITE_PUBLIC, 'favicon.ico'),
icon: join(process.env.PUBLIC, 'favicon.ico'),
webPreferences: {
preload,
// Warning: Enable nodeIntegration and disable contextIsolation is not secure in production

View File

@ -24,15 +24,14 @@
"preview": "vite preview"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.3.3",
"electron": "^26.0.0",
"electron-builder": "^24.6.3",
"tree-kill": "^1.2.2",
"typescript": "^5.1.6",
"vite": "^4.4.9",
"vite-plugin-electron": "^0.15.3",
"vite-plugin-electron-renderer": "^0.14.5",
"vue": "^3.3.4",
"vue-tsc": "^1.8.8"
"@vitejs/plugin-vue": "^4.1.0",
"electron": "^24.1.3",
"electron-builder": "^23.6.0",
"typescript": "^5.0.2",
"vite": "^4.1.4",
"vite-plugin-electron": "^0.11.2",
"vite-plugin-electron-renderer": "^0.14.1",
"vue": "^3.2.47",
"vue-tsc": "^1.2.0"
}
}

View File

@ -1,5 +1,7 @@
<script setup lang="ts">
import HelloWorld from './components/HelloWorld.vue'
console.log("[App.vue]", `Hello world from Electron ${process.versions.electron}!`)
</script>
<template>

View File

@ -3,7 +3,6 @@ import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import electron from 'vite-plugin-electron'
import renderer from 'vite-plugin-electron-renderer'
import { notBundle } from 'vite-plugin-electron/plugin'
import pkg from './package.json'
// https://vitejs.dev/config/
@ -19,13 +18,13 @@ export default defineConfig(({ command }) => {
vue(),
electron([
{
// Main process entry file of the Electron App.
// Main-Process entry file of the Electron App.
entry: 'electron/main/index.ts',
onstart({ startup }) {
onstart(options) {
if (process.env.VSCODE_DEBUG) {
console.log(/* For `.vscode/.debug.script.mjs` */'[startup] Electron App')
} else {
startup()
options.startup()
}
},
vite: {
@ -34,26 +33,17 @@ export default defineConfig(({ command }) => {
minify: isBuild,
outDir: 'dist-electron/main',
rollupOptions: {
// Some third-party Node.js libraries may not be built correctly by Vite, especially `C/C++` addons,
// we can use `external` to exclude them to ensure they work correctly.
// Others need to put them in `dependencies` to ensure they are collected into `app.asar` after the app is built.
// Of course, this is not absolute, just this way is relatively simple. :)
external: Object.keys('dependencies' in pkg ? pkg.dependencies : {}),
},
},
plugins: [
// This is just an option to improve build performance, it's non-deterministic!
// e.g. `import log from 'electron-log'` -> `const log = require('electron-log')`
isServe && notBundle(),
],
},
},
{
entry: 'electron/preload/index.ts',
onstart({ reload }) {
// Notify the Renderer process to reload the page when the Preload scripts build is complete,
onstart(options) {
// Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete,
// instead of restarting the entire Electron App.
reload()
options.reload()
},
vite: {
build: {
@ -64,13 +54,10 @@ export default defineConfig(({ command }) => {
external: Object.keys('dependencies' in pkg ? pkg.dependencies : {}),
},
},
plugins: [
isServe && notBundle(),
],
},
}
]),
// Use Node.js API in the Renderer process
// Use Node.js API in the Renderer-process
renderer(),
],
server: process.env.VSCODE_DEBUG && (() => {