vue-cli-plugin-electron-haunv 1.0.2 ā 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/dev-runner.js +71 -0
- package/bin/hot-reload.js +1 -0
- package/generator/index.js +29 -0
- package/generator/template/electron/main.js +30 -0
- package/generator/template/electron/preload.js +5 -0
- package/index.js +8 -41
- package/package.json +16 -56
- package/LICENSE +0 -21
- package/README.md +0 -250
- package/bin/cli.js +0 -87
- package/generator/template/index.html +0 -15
- package/generator/template/package.json +0 -28
- package/generator/template/src/App.vue +0 -125
- package/generator/template/src/background.js +0 -88
- package/generator/template/src/main.js +0 -4
- package/generator/template/src/preload.js +0 -31
- package/generator/template/vite.config.js +0 -36
- package/index.d.ts +0 -180
- package/lib/build.js +0 -128
- package/lib/config.js +0 -25
- package/lib/nativeDeps.js +0 -85
- package/lib/plugin.js +0 -40
- package/lib/protocol.js +0 -55
- package/lib/serve.js +0 -99
- package/lib/vitePlugin.js +0 -65
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const { spawn } = require("child_process")
|
|
2
|
+
const waitOn = require("wait-on")
|
|
3
|
+
const getPort = require("get-port").default
|
|
4
|
+
const chokidar = require("chokidar")
|
|
5
|
+
const kill = require("tree-kill")
|
|
6
|
+
const electron = require("electron")
|
|
7
|
+
|
|
8
|
+
let electronProcess
|
|
9
|
+
let port
|
|
10
|
+
let reloadTimeout
|
|
11
|
+
|
|
12
|
+
function startElectron() {
|
|
13
|
+
|
|
14
|
+
electronProcess = spawn(
|
|
15
|
+
electron,
|
|
16
|
+
["."],
|
|
17
|
+
{
|
|
18
|
+
stdio: "inherit",
|
|
19
|
+
env: {
|
|
20
|
+
...process.env,
|
|
21
|
+
VITE_DEV_SERVER_URL: `http://localhost:${port}`
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function restartElectron() {
|
|
29
|
+
|
|
30
|
+
clearTimeout(reloadTimeout)
|
|
31
|
+
|
|
32
|
+
reloadTimeout = setTimeout(() => {
|
|
33
|
+
if (electronProcess) {
|
|
34
|
+
electronProcess.kill()
|
|
35
|
+
startElectron()
|
|
36
|
+
}
|
|
37
|
+
}, 300)
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function run() {
|
|
42
|
+
|
|
43
|
+
port = await getPort({
|
|
44
|
+
port: [8080, 8081, 8082, 8083]
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
spawn(
|
|
48
|
+
"npm",
|
|
49
|
+
["run", "serve", "--", "--port", port],
|
|
50
|
+
{
|
|
51
|
+
stdio: "inherit",
|
|
52
|
+
shell: true
|
|
53
|
+
}
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
await waitOn({
|
|
57
|
+
resources: [`http://localhost:${port}`]
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
startElectron()
|
|
61
|
+
|
|
62
|
+
chokidar
|
|
63
|
+
.watch(["electron"], {
|
|
64
|
+
ignored: /node_modules/,
|
|
65
|
+
ignoreInitial: true
|
|
66
|
+
})
|
|
67
|
+
.on("all", restartElectron)
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
run()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// custom reload
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module.exports = (api) => {
|
|
2
|
+
|
|
3
|
+
api.render('./template')
|
|
4
|
+
|
|
5
|
+
api.extendPackage({
|
|
6
|
+
|
|
7
|
+
main: "electron/main.js",
|
|
8
|
+
|
|
9
|
+
build: {
|
|
10
|
+
appId: "com.haunv.app",
|
|
11
|
+
productName: "MyApp",
|
|
12
|
+
directories: {
|
|
13
|
+
output: "dist_electron"
|
|
14
|
+
},
|
|
15
|
+
files: [
|
|
16
|
+
"dist/**/*",
|
|
17
|
+
"electron/**/*"
|
|
18
|
+
],
|
|
19
|
+
win: {
|
|
20
|
+
target: [
|
|
21
|
+
"nsis",
|
|
22
|
+
"portable"
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const { app, BrowserWindow } = require("electron")
|
|
2
|
+
|
|
3
|
+
let mainWindow
|
|
4
|
+
|
|
5
|
+
function createWindow() {
|
|
6
|
+
|
|
7
|
+
mainWindow = new BrowserWindow({
|
|
8
|
+
width: 1200,
|
|
9
|
+
height: 800,
|
|
10
|
+
webPreferences: {
|
|
11
|
+
preload: require("path").join(__dirname, "preload.js"),
|
|
12
|
+
contextIsolation: true,
|
|
13
|
+
nodeIntegration: false
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
if (process.env.VITE_DEV_SERVER_URL) {
|
|
18
|
+
mainWindow.loadURL(process.env.VITE_DEV_SERVER_URL)
|
|
19
|
+
mainWindow.webContents.openDevTools()
|
|
20
|
+
} else {
|
|
21
|
+
mainWindow.loadFile("dist/index.html")
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
app.whenReady().then(createWindow)
|
|
27
|
+
|
|
28
|
+
app.on("window-all-closed", () => {
|
|
29
|
+
if (process.platform !== "darwin") app.quit()
|
|
30
|
+
})
|
package/index.js
CHANGED
|
@@ -1,41 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* import { createElectronPlugin } from 'vite-plugin-electron-builder'
|
|
10
|
-
*
|
|
11
|
-
* export default defineConfig({
|
|
12
|
-
* plugins: [vue(), createElectronPlugin({ mainProcessFile: 'src/background.js' })]
|
|
13
|
-
* })
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
const { createElectronPlugin } = require('./lib/vitePlugin')
|
|
17
|
-
const { electronServePlugin, electronBuildPlugin } = require('./lib/plugin')
|
|
18
|
-
const { buildRenderer, buildMain } = require('./lib/build')
|
|
19
|
-
const { serve } = require('./lib/serve')
|
|
20
|
-
const { createProtocol } = require('./lib/protocol')
|
|
21
|
-
const { getNativeDeps } = require('./lib/nativeDeps')
|
|
22
|
-
const { getConfig } = require('./lib/config')
|
|
23
|
-
|
|
24
|
-
module.exports = {
|
|
25
|
-
// Primary API ā use this in vite.config.js
|
|
26
|
-
createElectronPlugin,
|
|
27
|
-
|
|
28
|
-
// Lower-level Vite plugin hooks (serve / build separately)
|
|
29
|
-
electronServePlugin,
|
|
30
|
-
electronBuildPlugin,
|
|
31
|
-
|
|
32
|
-
// Build utilities
|
|
33
|
-
buildRenderer,
|
|
34
|
-
buildMain,
|
|
35
|
-
serve,
|
|
36
|
-
|
|
37
|
-
// Helpers (importable directly too via their lib path)
|
|
38
|
-
createProtocol,
|
|
39
|
-
getNativeDeps,
|
|
40
|
-
getConfig,
|
|
41
|
-
}
|
|
1
|
+
module.exports = (api) => {
|
|
2
|
+
api.extendPackage({
|
|
3
|
+
scripts: {
|
|
4
|
+
"electron:dev": "node node_modules/vue-cli-plugin-electron-haunv/bin/dev-runner.js",
|
|
5
|
+
"electron:build": "electron-builder"
|
|
6
|
+
}
|
|
7
|
+
})
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,64 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-cli-plugin-electron-haunv",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Easily Build Your Vue 3 + Vite App For Desktop With Electron",
|
|
3
|
+
"version": "1.0.3",
|
|
5
4
|
"main": "index.js",
|
|
6
|
-
"types": "index.d.ts",
|
|
7
|
-
"bin": {
|
|
8
|
-
"vite-electron": "./bin/cli.js",
|
|
9
|
-
"create-electron-vue": "./bin/cli.js"
|
|
10
|
-
},
|
|
11
|
-
"keywords": [
|
|
12
|
-
"vue",
|
|
13
|
-
"vue3",
|
|
14
|
-
"vite",
|
|
15
|
-
"electron",
|
|
16
|
-
"electron-builder",
|
|
17
|
-
"desktop",
|
|
18
|
-
"plugin",
|
|
19
|
-
"boilerplate"
|
|
20
|
-
],
|
|
21
|
-
"author": "",
|
|
22
5
|
"license": "MIT",
|
|
23
|
-
|
|
24
|
-
"node": ">=18.0.0"
|
|
25
|
-
},
|
|
6
|
+
|
|
26
7
|
"files": [
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"bin/",
|
|
31
|
-
"generator/"
|
|
8
|
+
"generator",
|
|
9
|
+
"bin",
|
|
10
|
+
"index.js"
|
|
32
11
|
],
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
},
|
|
37
|
-
"peerDependenciesMeta": {
|
|
38
|
-
"electron": {
|
|
39
|
-
"optional": false
|
|
40
|
-
},
|
|
41
|
-
"vite": {
|
|
42
|
-
"optional": false
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
"dependencies": {
|
|
46
|
-
"chalk": "^4.1.2",
|
|
47
|
-
"chokidar": "^3.6.0",
|
|
48
|
-
"commander": "^14.0.3",
|
|
49
|
-
"electron-builder": "^26.8.1",
|
|
50
|
-
"esbuild": "^0.27.4",
|
|
51
|
-
"execa": "^5.1.1",
|
|
52
|
-
"fs-extra": "^11.3.4",
|
|
53
|
-
"semver": "^7.7.4"
|
|
54
|
-
},
|
|
12
|
+
|
|
13
|
+
"dependencies": {},
|
|
14
|
+
|
|
55
15
|
"devDependencies": {
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
16
|
+
"electron": "latest",
|
|
17
|
+
"electron-builder": "latest",
|
|
18
|
+
"concurrently": "latest",
|
|
19
|
+
"wait-on": "latest",
|
|
20
|
+
"chokidar": "latest",
|
|
21
|
+
"tree-kill": "latest",
|
|
22
|
+
"get-port": "latest"
|
|
63
23
|
}
|
|
64
|
-
}
|
|
24
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/README.md
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
# vite-plugin-electron-builder
|
|
2
|
-
|
|
3
|
-
> Easily Build Your Vue 3 + Vite App For Desktop With Electron
|
|
4
|
-
|
|
5
|
-
[](https://github.com/your-username/vite-plugin-electron-builder/actions/workflows/nodeCI.yml)
|
|
6
|
-
[](https://www.npmjs.com/package/vite-plugin-electron-builder)
|
|
7
|
-
[](./LICENSE)
|
|
8
|
-
|
|
9
|
-
A modern replacement for `vue-cli-plugin-electron-builder`, built on top of **Vite 8**, **Electron 41**, and **electron-builder 26**. All dependencies are kept at their latest versions.
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## ⨠Features
|
|
14
|
-
|
|
15
|
-
- ā” **Vite-native** ā instant HMR for the renderer process
|
|
16
|
-
- š **Auto-restart** ā watches your main process files and restarts Electron on change
|
|
17
|
-
- š **Secure by default** ā custom `app://` protocol with path traversal protection, context isolation enabled
|
|
18
|
-
- š **esbuild** ā fast TypeScript/ESM compilation for the main process
|
|
19
|
-
- š **Playwright** ā built-in E2E test helper for Electron windows
|
|
20
|
-
- š¦ **electron-builder** ā full packaging for Linux, macOS, and Windows
|
|
21
|
-
- š„ **CLI** ā scaffold a new project with one command
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
## Quick Start
|
|
26
|
-
|
|
27
|
-
### Scaffold a new project
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
npx vite-plugin-electron-builder my-app
|
|
31
|
-
cd my-app
|
|
32
|
-
npm run electron:serve
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### Add to an existing Vite + Vue project
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
npm install -D vite-plugin-electron-builder electron electron-builder esbuild
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
Then update your `vite.config.js`:
|
|
42
|
-
|
|
43
|
-
```js
|
|
44
|
-
import { defineConfig } from 'vite'
|
|
45
|
-
import vue from '@vitejs/plugin-vue'
|
|
46
|
-
import { createElectronPlugin } from 'vite-plugin-electron-builder'
|
|
47
|
-
|
|
48
|
-
export default defineConfig({
|
|
49
|
-
plugins: [
|
|
50
|
-
vue(),
|
|
51
|
-
createElectronPlugin({
|
|
52
|
-
mainProcessFile: 'src/background.js',
|
|
53
|
-
outputDir: 'dist_electron',
|
|
54
|
-
}),
|
|
55
|
-
],
|
|
56
|
-
})
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
Add scripts to your `package.json`:
|
|
60
|
-
|
|
61
|
-
```json
|
|
62
|
-
{
|
|
63
|
-
"scripts": {
|
|
64
|
-
"electron:serve": "vite-electron serve",
|
|
65
|
-
"electron:build": "vite build && vite-electron build"
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
---
|
|
71
|
-
|
|
72
|
-
## Project Structure
|
|
73
|
-
|
|
74
|
-
After scaffolding, your project will look like this:
|
|
75
|
-
|
|
76
|
-
```
|
|
77
|
-
my-app/
|
|
78
|
-
āāā src/
|
|
79
|
-
ā āāā App.vue # Vue renderer component
|
|
80
|
-
ā āāā main.js # Renderer entry point
|
|
81
|
-
ā āāā background.js # Electron main process ā edit this
|
|
82
|
-
ā āāā preload.js # Preload script (contextBridge)
|
|
83
|
-
āāā tests/
|
|
84
|
-
ā āāā e2e/
|
|
85
|
-
ā āāā app.spec.js # Playwright E2E tests
|
|
86
|
-
āāā index.html
|
|
87
|
-
āāā vite.config.js
|
|
88
|
-
āāā package.json
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
---
|
|
92
|
-
|
|
93
|
-
## Plugin Options
|
|
94
|
-
|
|
95
|
-
```ts
|
|
96
|
-
interface ElectronBuilderOptions {
|
|
97
|
-
/** Electron main process entry file. Default: 'src/background.js' */
|
|
98
|
-
mainProcessFile?: string
|
|
99
|
-
|
|
100
|
-
/** Output dir for compiled main process. Default: 'dist_electron' */
|
|
101
|
-
outputDir?: string
|
|
102
|
-
|
|
103
|
-
/** Preload script path. Optional. */
|
|
104
|
-
preload?: string
|
|
105
|
-
|
|
106
|
-
/** Enable Node integration in renderer. Default: false */
|
|
107
|
-
nodeIntegration?: boolean
|
|
108
|
-
|
|
109
|
-
/** Enable context isolation. Default: true */
|
|
110
|
-
contextIsolation?: boolean
|
|
111
|
-
|
|
112
|
-
/** Custom protocol scheme name. Default: 'app' */
|
|
113
|
-
customFileProtocol?: string
|
|
114
|
-
|
|
115
|
-
/** Extra Electron CLI flags for development. */
|
|
116
|
-
electronCliArgs?: string[]
|
|
117
|
-
|
|
118
|
-
/** electron-builder config overrides. */
|
|
119
|
-
builderOptions?: import('electron-builder').Configuration
|
|
120
|
-
|
|
121
|
-
/** Native modules to externalize from the bundle. */
|
|
122
|
-
externals?: string[]
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
---
|
|
127
|
-
|
|
128
|
-
## Development
|
|
129
|
-
|
|
130
|
-
### Commands
|
|
131
|
-
|
|
132
|
-
| Command | Description |
|
|
133
|
-
|---|---|
|
|
134
|
-
| `npm run electron:serve` | Start Vite dev server + Electron |
|
|
135
|
-
| `npm run electron:build` | Build renderer + package with electron-builder |
|
|
136
|
-
| `npm test` | Run Jest unit tests |
|
|
137
|
-
| `npm run test:e2e` | Run Playwright E2E tests |
|
|
138
|
-
| `npm run lint` | ESLint |
|
|
139
|
-
|
|
140
|
-
### How it works
|
|
141
|
-
|
|
142
|
-
**Development (`electron:serve`)**
|
|
143
|
-
|
|
144
|
-
1. Vite starts its dev server (default `:8080`)
|
|
145
|
-
2. The plugin compiles `src/background.js` with esbuild ā `dist_electron/main.js`
|
|
146
|
-
3. Electron is launched pointing at the Vite dev server URL
|
|
147
|
-
4. chokidar watches `src/background.js` (and preload) ā on change, recompiles and restarts Electron
|
|
148
|
-
|
|
149
|
-
**Production (`electron:build`)**
|
|
150
|
-
|
|
151
|
-
1. Vite builds the renderer to `dist/`
|
|
152
|
-
2. esbuild compiles and bundles the main process to `dist_electron/main.js`
|
|
153
|
-
3. electron-builder packages everything into a distributable (`.dmg`, `.exe`, `.AppImage`, etc.)
|
|
154
|
-
|
|
155
|
-
---
|
|
156
|
-
|
|
157
|
-
## Security
|
|
158
|
-
|
|
159
|
-
This plugin follows Electron security best practices:
|
|
160
|
-
|
|
161
|
-
- **Context isolation** is enabled by default (`contextIsolation: true`)
|
|
162
|
-
- **Node integration** is disabled by default in the renderer
|
|
163
|
-
- The custom `app://` protocol prevents path traversal attacks
|
|
164
|
-
- The preload template uses `contextBridge` to expose only whitelisted APIs
|
|
165
|
-
|
|
166
|
-
---
|
|
167
|
-
|
|
168
|
-
## API Reference
|
|
169
|
-
|
|
170
|
-
### `createElectronPlugin(options?)`
|
|
171
|
-
|
|
172
|
-
Returns a Vite plugin. Add it to the `plugins` array in `vite.config.js`.
|
|
173
|
-
|
|
174
|
-
### `createProtocol(scheme, basePath?)`
|
|
175
|
-
|
|
176
|
-
Registers a secure Electron file protocol. Import in your main process:
|
|
177
|
-
|
|
178
|
-
```js
|
|
179
|
-
import { createProtocol } from 'vite-plugin-electron-builder/lib/protocol'
|
|
180
|
-
|
|
181
|
-
app.whenReady().then(() => {
|
|
182
|
-
createProtocol('app')
|
|
183
|
-
win.loadURL('app://./index.html')
|
|
184
|
-
})
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
### `testWithPlaywright(options?)`
|
|
188
|
-
|
|
189
|
-
Launches Electron with Playwright for E2E tests:
|
|
190
|
-
|
|
191
|
-
```js
|
|
192
|
-
import { testWithPlaywright } from 'vite-plugin-electron-builder'
|
|
193
|
-
|
|
194
|
-
let app, page, stop
|
|
195
|
-
|
|
196
|
-
beforeAll(async () => {
|
|
197
|
-
;({ app, page, stop } = await testWithPlaywright({
|
|
198
|
-
appPath: 'dist_electron/main.js',
|
|
199
|
-
}))
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
afterAll(() => stop())
|
|
203
|
-
|
|
204
|
-
test('renders app', async () => {
|
|
205
|
-
const el = await page.$('#app')
|
|
206
|
-
expect(el).not.toBeNull()
|
|
207
|
-
})
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
---
|
|
211
|
-
|
|
212
|
-
## Package Versions
|
|
213
|
-
|
|
214
|
-
All dependencies are pinned to their latest major versions:
|
|
215
|
-
|
|
216
|
-
| Package | Version |
|
|
217
|
-
|---|---|
|
|
218
|
-
| `electron` | ^41.0.2 |
|
|
219
|
-
| `electron-builder` | ^26.8.1 |
|
|
220
|
-
| `vite` | ^8.0.0 |
|
|
221
|
-
| `@vitejs/plugin-vue` | ^6.0.5 |
|
|
222
|
-
| `esbuild` | ^0.27.4 |
|
|
223
|
-
| `@playwright/test` | ^1.58.2 |
|
|
224
|
-
| `chalk` | ^5.6.2 |
|
|
225
|
-
| `chokidar` | ^5.0.0 |
|
|
226
|
-
| `commander` | ^14.0.3 |
|
|
227
|
-
| `execa` | ^9.6.1 |
|
|
228
|
-
| `fs-extra` | ^11.3.4 |
|
|
229
|
-
| `semver` | ^7.7.4 |
|
|
230
|
-
| `concurrently` | ^9.2.1 |
|
|
231
|
-
| `wait-on` | ^9.0.4 |
|
|
232
|
-
|
|
233
|
-
---
|
|
234
|
-
|
|
235
|
-
## Migrating from vue-cli-plugin-electron-builder
|
|
236
|
-
|
|
237
|
-
| vue-cli-plugin | vite-plugin-electron-builder |
|
|
238
|
-
|---|---|
|
|
239
|
-
| `vue add electron-builder` | `npx vite-plugin-electron-builder my-app` |
|
|
240
|
-
| `vue-cli-service electron:serve` | `vite-electron serve` |
|
|
241
|
-
| `vue-cli-service electron:build` | `vite-electron build` |
|
|
242
|
-
| `vue.config.js` plugin options | `vite.config.js` `createElectronPlugin({})` |
|
|
243
|
-
| `background.js` | `src/background.js` (unchanged) |
|
|
244
|
-
| `createProtocol` | `import { createProtocol } from 'vite-plugin-electron-builder/lib/protocol'` |
|
|
245
|
-
|
|
246
|
-
---
|
|
247
|
-
|
|
248
|
-
## License
|
|
249
|
-
|
|
250
|
-
MIT
|
package/bin/cli.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
'use strict'
|
|
4
|
-
|
|
5
|
-
const { program } = require('commander')
|
|
6
|
-
const path = require('path')
|
|
7
|
-
const chalk = require('chalk')
|
|
8
|
-
const pkg = require('../package.json')
|
|
9
|
-
|
|
10
|
-
program
|
|
11
|
-
.name('vite-electron')
|
|
12
|
-
.description('Vite Plugin Electron Builder CLI')
|
|
13
|
-
.version(pkg.version)
|
|
14
|
-
|
|
15
|
-
program
|
|
16
|
-
.command('serve')
|
|
17
|
-
.description('Start the Electron development server')
|
|
18
|
-
.option('--main <file>', 'Path to main process file', 'src/background.js')
|
|
19
|
-
.option('--out <dir>', 'Output directory', 'dist_electron')
|
|
20
|
-
.action(async (opts) => {
|
|
21
|
-
const { createServer } = require('vite')
|
|
22
|
-
const { serveElectron } = require('../lib/build')
|
|
23
|
-
|
|
24
|
-
console.log(chalk.cyan('\nš Starting Vite + Electron dev server...\n'))
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
// Start Vite dev server
|
|
28
|
-
const viteServer = await createServer({
|
|
29
|
-
base: './',
|
|
30
|
-
server: { port: 8080 }
|
|
31
|
-
})
|
|
32
|
-
await viteServer.listen()
|
|
33
|
-
viteServer.printUrls()
|
|
34
|
-
|
|
35
|
-
// Start Electron in watch mode
|
|
36
|
-
const { stop } = await serveElectron({
|
|
37
|
-
mainProcessFile: opts.main,
|
|
38
|
-
outputDir: opts.out
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
// Handle graceful shutdown
|
|
42
|
-
const shutdown = async () => {
|
|
43
|
-
console.log(chalk.yellow('\n[electron-builder] Shutting down...'))
|
|
44
|
-
await stop()
|
|
45
|
-
await viteServer.close()
|
|
46
|
-
process.exit(0)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
process.on('SIGINT', shutdown)
|
|
50
|
-
process.on('SIGTERM', shutdown)
|
|
51
|
-
} catch (err) {
|
|
52
|
-
console.error(chalk.red('[electron-builder] Serve failed:'), err)
|
|
53
|
-
process.exit(1)
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
program
|
|
58
|
-
.command('build')
|
|
59
|
-
.description('Build the app for production')
|
|
60
|
-
.option('--main <file>', 'Path to main process file', 'src/background.js')
|
|
61
|
-
.option('--out <dir>', 'Output directory', 'dist_electron')
|
|
62
|
-
.option('--platform <platform>', 'Target platform (linux|mac|win)')
|
|
63
|
-
.action(async (opts) => {
|
|
64
|
-
const { buildElectron } = require('../lib/build')
|
|
65
|
-
|
|
66
|
-
console.log(chalk.cyan('\nš¦ Building for production...\n'))
|
|
67
|
-
|
|
68
|
-
try {
|
|
69
|
-
await buildElectron({
|
|
70
|
-
mainProcessFile: opts.main,
|
|
71
|
-
outputDir: opts.out,
|
|
72
|
-
builderOptions: opts.platform
|
|
73
|
-
? { [opts.platform]: {} }
|
|
74
|
-
: {}
|
|
75
|
-
})
|
|
76
|
-
} catch (err) {
|
|
77
|
-
console.error(chalk.red('[electron-builder] Build failed:'), err)
|
|
78
|
-
process.exit(1)
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
program.parse(process.argv)
|
|
83
|
-
|
|
84
|
-
// Show help if no command given
|
|
85
|
-
if (!process.argv.slice(2).length) {
|
|
86
|
-
program.outputHelp()
|
|
87
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
-
<!-- Required for Electron security -->
|
|
7
|
-
<meta http-equiv="Content-Security-Policy"
|
|
8
|
-
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline';" />
|
|
9
|
-
<title>Vue 3 + Vite + Electron</title>
|
|
10
|
-
</head>
|
|
11
|
-
<body>
|
|
12
|
-
<div id="app"></div>
|
|
13
|
-
<script type="module" src="/src/main.js"></script>
|
|
14
|
-
</body>
|
|
15
|
-
</html>
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "my-electron-vue-app",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"description": "A Vue 3 + Vite + Electron desktop application",
|
|
5
|
-
"main": "dist_electron/main.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"dev": "vite",
|
|
8
|
-
"build": "vite build",
|
|
9
|
-
"electron:serve": "vite-electron serve",
|
|
10
|
-
"electron:build": "vite build && vite-electron build"
|
|
11
|
-
},
|
|
12
|
-
"keywords": [],
|
|
13
|
-
"author": "",
|
|
14
|
-
"license": "MIT",
|
|
15
|
-
"engines": {
|
|
16
|
-
"node": ">=18.0.0"
|
|
17
|
-
},
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"vue": "^3.5.13"
|
|
20
|
-
},
|
|
21
|
-
"devDependencies": {
|
|
22
|
-
"@vitejs/plugin-vue": "^6.0.5",
|
|
23
|
-
"electron": "^41.0.2",
|
|
24
|
-
"electron-devtools-installer": "^4.0.0",
|
|
25
|
-
"vite": "^8.0.0",
|
|
26
|
-
"vite-plugin-electron-builder": "^1.0.0"
|
|
27
|
-
}
|
|
28
|
-
}
|