vue-cli-plugin-electron-haunv 1.0.16 → 1.0.17

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/README.md CHANGED
@@ -1,2 +1,187 @@
1
- # vue-cli-plugin-electron-haunv
2
- build electron in vue cli
1
+ # vue-cli-plugin-electron-haunv
2
+
3
+ > A Vue CLI plugin for building Windows desktop apps with Electron.
4
+
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ vue add electron-haunv
11
+ ```
12
+
13
+ After running, the following will be generated:
14
+
15
+ ```
16
+ my-app/
17
+ ├── electron/
18
+ │ ├── main.js # Electron main process
19
+ │ └── preload.js # Preload script (contextBridge)
20
+ ├── electron-builder.json
21
+ └── ...
22
+ ```
23
+
24
+ ---
25
+
26
+ ## Commands
27
+
28
+ | Command | Description |
29
+ |---------|-------------|
30
+ | `npm run electron:dev` | Start in development mode with hot-reload |
31
+ | `npm run electron:build` | Build a Windows installer |
32
+
33
+ ---
34
+
35
+ ## Configuration
36
+
37
+ All build settings are in **`electron-builder.json`**:
38
+
39
+ ```json
40
+ {
41
+ "appId": "com.haunv.app",
42
+ "productName": "MyApp",
43
+ "directories": {
44
+ "output": "dist_electron"
45
+ },
46
+ "files": [
47
+ "dist/**/*",
48
+ "electron/**/*",
49
+ "package.json"
50
+ ],
51
+ "extraMetadata": {
52
+ "main": "electron/main.js"
53
+ },
54
+ "win": {
55
+ "target": [
56
+ {
57
+ "target": "nsis",
58
+ "arch": [
59
+ "x64"
60
+ ]
61
+ },
62
+ {
63
+ "target": "portable",
64
+ "arch": [
65
+ "x64"
66
+ ]
67
+ }
68
+ ]
69
+ },
70
+ "nsis": {
71
+ "oneClick": false,
72
+ "allowToChangeInstallationDirectory": true
73
+ }
74
+ }
75
+ ```
76
+
77
+ ---
78
+
79
+ ## Main Process (`electron/main.js`)
80
+
81
+ ```javascript
82
+ const { app, BrowserWindow } = require("electron")
83
+ const path = require("path")
84
+ const { installExtension, VUEJS_DEVTOOLS } = require('@tomjs/electron-devtools-installer');
85
+
86
+ const isDevelopment = process.env.NODE_ENV !== 'production'
87
+ function createWindow() {
88
+
89
+ const win = new BrowserWindow({
90
+ width: 1200,
91
+ height: 800,
92
+ webPreferences: {
93
+ preload: path.join(__dirname, "preload.js"),
94
+ contextIsolation: true
95
+ }
96
+ })
97
+
98
+ const isDev = !!process.env.DEV_SERVER_URL
99
+
100
+ if (isDev) {
101
+ win.loadURL(process.env.DEV_SERVER_URL)
102
+ win.webContents.openDevTools()
103
+ } else {
104
+ const indexPath = path.join(__dirname, "../dist/index.html")
105
+
106
+ win.loadFile(indexPath)
107
+ }
108
+ }
109
+
110
+ app.whenReady().then(async () => {
111
+
112
+ if (isDevelopment && !process.env.IS_TEST) {
113
+ installExtension(VUEJS_DEVTOOLS)
114
+ .then(ext => console.log(`Added Extension: ${ext.name}`))
115
+ .catch(err => console.log('An error occurred: ', err));
116
+ }
117
+
118
+ createWindow()
119
+ })
120
+
121
+ app.on("window-all-closed", () => {
122
+ if (process.platform !== "darwin") app.quit()
123
+ })
124
+ ```
125
+
126
+ ---
127
+
128
+ ## Preload Script (`electron/preload.js`)
129
+
130
+ Safely expose APIs from the main process to the renderer (Vue app):
131
+
132
+ ```javascript
133
+ const { contextBridge, ipcRenderer } = require('electron')
134
+
135
+ contextBridge.exposeInMainWorld('electronAPI', {
136
+ send: (channel, data) => ipcRenderer.send(channel, data),
137
+ on: (channel, callback) => ipcRenderer.on(channel, (_, ...args) => callback(...args)),
138
+ invoke: (channel, data) => ipcRenderer.invoke(channel, data)
139
+ })
140
+ ```
141
+
142
+ Use in any Vue component:
143
+
144
+ ```javascript
145
+ window.electronAPI.send('my-event', payload)
146
+ window.electronAPI.on('my-response', (data) => console.log(data))
147
+ ```
148
+
149
+ > **Note:** Restart `npm run electron:dev` after editing `preload.js`.
150
+
151
+ ---
152
+
153
+ ## Environment Variables
154
+
155
+ Variables prefixed with `VUE_APP_` are accessible in both the main process and the renderer:
156
+
157
+ ```bash
158
+ # .env
159
+ VUE_APP_API_URL=https://api.example.com
160
+ ```
161
+
162
+ ```javascript
163
+ console.log(process.env.VUE_APP_API_URL)
164
+ ```
165
+
166
+ | Variable | Description |
167
+ |----------|-------------|
168
+ | `process.env.WEBPACK_DEV_SERVER_URL` | Set in development mode only |
169
+ | `process.env.IS_TEST` | `true` when running tests |
170
+
171
+ ---
172
+
173
+ ## Static Assets
174
+
175
+ Place static files in `public/` and access them via `__static`:
176
+
177
+ ```javascript
178
+ // In main.js
179
+ import path from 'path'
180
+ const icon = path.join(__static, 'icon.png')
181
+ ```
182
+
183
+ ---
184
+
185
+ ## License
186
+
187
+ MIT © haunv
@@ -1,5 +1,5 @@
1
1
  const { contextBridge } = require("electron")
2
2
 
3
- contextBridge.exposeInMainWorld("api", {
3
+ contextBridge.exposeInMainWorld("electronAPI", {
4
4
  ping: () => "pong"
5
5
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-cli-plugin-electron-haunv",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "keywords": [