mirror of
https://github.com/electron-vite/electron-vite-vue
synced 2025-09-03 04:57:37 +08:00
Compare commits
14 Commits
3d3daf1db5
...
v2.2.0
Author | SHA1 | Date | |
---|---|---|---|
|
b9e6647581 | ||
|
fc17f328a4 | ||
|
7e1e590ab4 | ||
|
1b77a3893c | ||
|
d3b9cca7b9 | ||
|
690c58d20b | ||
|
e1425fb8e8 | ||
|
c306cd51e2 | ||
|
237790b0d9 | ||
|
72a74b89d8 | ||
|
36ae4e4421 | ||
|
76846513db | ||
|
b4cf3b4c5f | ||
|
69e11a78ac |
6
.npmrc
Normal file
6
.npmrc
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# For electron-builder
|
||||||
|
# https://github.com/electron-userland/electron-builder/issues/6289#issuecomment-1042620422
|
||||||
|
shamefully-hoist=true
|
||||||
|
|
||||||
|
# For China 🇨🇳 developers
|
||||||
|
# electron_mirror=https://npmmirror.com/mirrors/electron/
|
18
README.md
18
README.md
@@ -19,16 +19,22 @@
|
|||||||
🔩 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 Start
|
## Quick Setup
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
npm create electron-vite
|
# 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
|
||||||
```
|
```
|
||||||
|
|
||||||
<!-- [](https://asciinema.org/a/483731) -->
|
|
||||||
|
|
||||||

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

|

|
||||||
|
@@ -5,18 +5,19 @@
|
|||||||
"$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-electron",
|
"dist",
|
||||||
"dist"
|
"dist-electron"
|
||||||
],
|
],
|
||||||
"mac": {
|
"mac": {
|
||||||
"artifactName": "${productName}_${version}.${ext}",
|
|
||||||
"target": [
|
"target": [
|
||||||
"dmg"
|
"dmg"
|
||||||
]
|
],
|
||||||
|
"artifactName": "${productName}-Mac-${version}-Installer.${ext}"
|
||||||
},
|
},
|
||||||
"win": {
|
"win": {
|
||||||
"target": [
|
"target": [
|
||||||
@@ -27,12 +28,18 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"artifactName": "${productName}_${version}.${ext}"
|
"artifactName": "${productName}-Windows-${version}-Setup.${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/ */
|
||||||
PUBLIC: string
|
VITE_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.PUBLIC = process.env.VITE_DEV_SERVER_URL
|
process.env.VITE_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.PUBLIC, 'favicon.ico'),
|
icon: join(process.env.VITE_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
|
||||||
|
21
package.json
21
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "electron-vue-vite",
|
"name": "electron-vue-vite",
|
||||||
"version": "2.0.0",
|
"version": "2.2.0",
|
||||||
"main": "dist-electron/main/index.js",
|
"main": "dist-electron/main/index.js",
|
||||||
"description": "Really simple Electron + Vue + Vite boilerplate.",
|
"description": "Really simple Electron + Vue + Vite boilerplate.",
|
||||||
"author": "草鞋没号 <308487730@qq.com>",
|
"author": "草鞋没号 <308487730@qq.com>",
|
||||||
@@ -24,14 +24,15 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vitejs/plugin-vue": "^4.1.0",
|
"@vitejs/plugin-vue": "^5.0.1",
|
||||||
"electron": "^25.0.1",
|
"electron": "^28.1.0",
|
||||||
"electron-builder": "^23.6.0",
|
"electron-builder": "^24.9.1",
|
||||||
"typescript": "^5.0.2",
|
"tree-kill": "^1.2.2",
|
||||||
"vite": "^4.1.4",
|
"typescript": "^5.3.3",
|
||||||
"vite-plugin-electron": "^0.11.2",
|
"vite": "^5.0.10",
|
||||||
"vite-plugin-electron-renderer": "^0.14.1",
|
"vite-plugin-electron": "^0.15.5",
|
||||||
"vue": "^3.2.47",
|
"vite-plugin-electron-renderer": "^0.14.5",
|
||||||
"vue-tsc": "^1.2.0"
|
"vue": "^3.4.1",
|
||||||
|
"vue-tsc": "^1.8.27"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,5 @@
|
|||||||
<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,6 +3,7 @@ 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/
|
||||||
@@ -18,13 +19,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(options) {
|
onstart({ startup }) {
|
||||||
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 {
|
||||||
options.startup()
|
startup()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
vite: {
|
vite: {
|
||||||
@@ -33,17 +34,26 @@ 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(options) {
|
onstart({ reload }) {
|
||||||
// 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.
|
||||||
options.reload()
|
reload()
|
||||||
},
|
},
|
||||||
vite: {
|
vite: {
|
||||||
build: {
|
build: {
|
||||||
@@ -54,10 +64,13 @@ 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 && (() => {
|
||||||
|
Reference in New Issue
Block a user