Compare commits
No commits in common. "690c58d20bb5b3416323f7bb18a00016b0722cd1" and "516234dce53bb92f35aea512e248d6f5d337b4b6" have entirely different histories.
690c58d20b
...
516234dce5
18
README.md
18
README.md
@ -19,22 +19,16 @@
|
|||||||
🔩 Support C/C++ native addons
|
🔩 Support C/C++ native addons
|
||||||
🖥 It's easy to implement multiple windows
|
🖥 It's easy to implement multiple windows
|
||||||
|
|
||||||
## Quick Setup
|
## Quick Start
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# clone the project
|
npm create electron-vite
|
||||||
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
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
<!-- [](https://asciinema.org/a/483731) -->
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Debug
|
## Debug
|
||||||
|
|
||||||

|

|
||||||
|
|||||||
@ -5,19 +5,18 @@
|
|||||||
"$schema": "https://raw.githubusercontent.com/electron-userland/electron-builder/master/packages/app-builder-lib/scheme.json",
|
"$schema": "https://raw.githubusercontent.com/electron-userland/electron-builder/master/packages/app-builder-lib/scheme.json",
|
||||||
"appId": "YourAppID",
|
"appId": "YourAppID",
|
||||||
"asar": true,
|
"asar": true,
|
||||||
"productName": "YourAppName",
|
|
||||||
"directories": {
|
"directories": {
|
||||||
"output": "release/${version}"
|
"output": "release/${version}"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist-electron",
|
||||||
"dist-electron"
|
"dist"
|
||||||
],
|
],
|
||||||
"mac": {
|
"mac": {
|
||||||
|
"artifactName": "${productName}_${version}.${ext}",
|
||||||
"target": [
|
"target": [
|
||||||
"dmg"
|
"dmg"
|
||||||
],
|
]
|
||||||
"artifactName": "${productName}-Mac-${version}-Installer.${ext}"
|
|
||||||
},
|
},
|
||||||
"win": {
|
"win": {
|
||||||
"target": [
|
"target": [
|
||||||
@ -28,18 +27,12 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"artifactName": "${productName}-Windows-${version}-Setup.${ext}"
|
"artifactName": "${productName}_${version}.${ext}"
|
||||||
},
|
},
|
||||||
"nsis": {
|
"nsis": {
|
||||||
"oneClick": false,
|
"oneClick": false,
|
||||||
"perMachine": false,
|
"perMachine": false,
|
||||||
"allowToChangeInstallationDirectory": true,
|
"allowToChangeInstallationDirectory": true,
|
||||||
"deleteAppDataOnUninstall": false
|
"deleteAppDataOnUninstall": false
|
||||||
},
|
|
||||||
"linux": {
|
|
||||||
"target": [
|
|
||||||
"AppImage"
|
|
||||||
],
|
|
||||||
"artifactName": "${productName}-Linux-${version}.${ext}"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
electron/electron-env.d.ts
vendored
2
electron/electron-env.d.ts
vendored
@ -6,6 +6,6 @@ declare namespace NodeJS {
|
|||||||
DIST_ELECTRON: string
|
DIST_ELECTRON: string
|
||||||
DIST: string
|
DIST: string
|
||||||
/** /dist/ or /public/ */
|
/** /dist/ or /public/ */
|
||||||
VITE_PUBLIC: string
|
PUBLIC: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import { join } from 'node:path'
|
|||||||
//
|
//
|
||||||
process.env.DIST_ELECTRON = join(__dirname, '..')
|
process.env.DIST_ELECTRON = join(__dirname, '..')
|
||||||
process.env.DIST = join(process.env.DIST_ELECTRON, '../dist')
|
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')
|
? join(process.env.DIST_ELECTRON, '../public')
|
||||||
: process.env.DIST
|
: process.env.DIST
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ const indexHtml = join(process.env.DIST, 'index.html')
|
|||||||
async function createWindow() {
|
async function createWindow() {
|
||||||
win = new BrowserWindow({
|
win = new BrowserWindow({
|
||||||
title: 'Main window',
|
title: 'Main window',
|
||||||
icon: join(process.env.VITE_PUBLIC, 'favicon.ico'),
|
icon: join(process.env.PUBLIC, 'favicon.ico'),
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload,
|
preload,
|
||||||
// Warning: Enable nodeIntegration and disable contextIsolation is not secure in production
|
// Warning: Enable nodeIntegration and disable contextIsolation is not secure in production
|
||||||
|
|||||||
19
package.json
19
package.json
@ -24,15 +24,14 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vitejs/plugin-vue": "^4.3.3",
|
"@vitejs/plugin-vue": "^4.1.0",
|
||||||
"electron": "^26.0.0",
|
"electron": "^24.1.3",
|
||||||
"electron-builder": "^24.6.3",
|
"electron-builder": "^23.6.0",
|
||||||
"tree-kill": "^1.2.2",
|
"typescript": "^5.0.2",
|
||||||
"typescript": "^5.1.6",
|
"vite": "^4.1.4",
|
||||||
"vite": "^4.4.9",
|
"vite-plugin-electron": "^0.11.2",
|
||||||
"vite-plugin-electron": "^0.15.3",
|
"vite-plugin-electron-renderer": "^0.14.1",
|
||||||
"vite-plugin-electron-renderer": "^0.14.5",
|
"vue": "^3.2.47",
|
||||||
"vue": "^3.3.4",
|
"vue-tsc": "^1.2.0"
|
||||||
"vue-tsc": "^1.8.8"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import HelloWorld from './components/HelloWorld.vue'
|
import HelloWorld from './components/HelloWorld.vue'
|
||||||
|
|
||||||
|
console.log("[App.vue]", `Hello world from Electron ${process.versions.electron}!`)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@ -3,7 +3,6 @@ import { defineConfig } from 'vite'
|
|||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import electron from 'vite-plugin-electron'
|
import electron from 'vite-plugin-electron'
|
||||||
import renderer from 'vite-plugin-electron-renderer'
|
import renderer from 'vite-plugin-electron-renderer'
|
||||||
import { notBundle } from 'vite-plugin-electron/plugin'
|
|
||||||
import pkg from './package.json'
|
import pkg from './package.json'
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
@ -19,13 +18,13 @@ export default defineConfig(({ command }) => {
|
|||||||
vue(),
|
vue(),
|
||||||
electron([
|
electron([
|
||||||
{
|
{
|
||||||
// Main process entry file of the Electron App.
|
// Main-Process entry file of the Electron App.
|
||||||
entry: 'electron/main/index.ts',
|
entry: 'electron/main/index.ts',
|
||||||
onstart({ startup }) {
|
onstart(options) {
|
||||||
if (process.env.VSCODE_DEBUG) {
|
if (process.env.VSCODE_DEBUG) {
|
||||||
console.log(/* For `.vscode/.debug.script.mjs` */'[startup] Electron App')
|
console.log(/* For `.vscode/.debug.script.mjs` */'[startup] Electron App')
|
||||||
} else {
|
} else {
|
||||||
startup()
|
options.startup()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
vite: {
|
vite: {
|
||||||
@ -34,26 +33,17 @@ export default defineConfig(({ command }) => {
|
|||||||
minify: isBuild,
|
minify: isBuild,
|
||||||
outDir: 'dist-electron/main',
|
outDir: 'dist-electron/main',
|
||||||
rollupOptions: {
|
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 : {}),
|
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',
|
entry: 'electron/preload/index.ts',
|
||||||
onstart({ reload }) {
|
onstart(options) {
|
||||||
// Notify the Renderer process to reload the page when the Preload scripts build is complete,
|
// Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete,
|
||||||
// instead of restarting the entire Electron App.
|
// instead of restarting the entire Electron App.
|
||||||
reload()
|
options.reload()
|
||||||
},
|
},
|
||||||
vite: {
|
vite: {
|
||||||
build: {
|
build: {
|
||||||
@ -64,13 +54,10 @@ export default defineConfig(({ command }) => {
|
|||||||
external: Object.keys('dependencies' in pkg ? pkg.dependencies : {}),
|
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(),
|
renderer(),
|
||||||
],
|
],
|
||||||
server: process.env.VSCODE_DEBUG && (() => {
|
server: process.env.VSCODE_DEBUG && (() => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user