@tomjs/vite-plugin-electron 1.9.3 → 2.0.0
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 +55 -39
- package/README.zh_CN.md +55 -39
- package/dist/electron-BUQU2XNS.mjs +8 -0
- package/dist/electron.d.mts +7 -0
- package/dist/electron.mjs +3 -0
- package/dist/index.d.mts +107 -106
- package/dist/index.mjs +406 -444
- package/package.json +48 -59
- package/dist/index.d.ts +0 -135
- package/dist/index.js +0 -493
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Many thanks to [caoxiemeihao](https://github.com/caoxiemeihao)'s [vite-plugin-el
|
|
|
10
10
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
13
|
-
- Fast build `main` and `preload` with [
|
|
13
|
+
- Fast build `main` and `preload` with [tsdwon](https://tsdown.dev/)
|
|
14
14
|
- Little configuration, focus on business
|
|
15
15
|
- Support `main`'s `Hot Restart`
|
|
16
16
|
- Support `preload`'s `Hot Reload`
|
|
@@ -90,10 +90,11 @@ See [PluginOptions](#pluginoptions) and `recommended` parameter descriptions in
|
|
|
90
90
|
```ts
|
|
91
91
|
import { dirname } from 'node:path';
|
|
92
92
|
import { fileURLToPath } from 'node:url';
|
|
93
|
+
import { ELECTRON_EXIT } from '@tomjs/vite-plugin-electron/electron';
|
|
93
94
|
import { app, BrowserWindow } from 'electron';
|
|
94
95
|
|
|
95
96
|
// when package.json "type": module"
|
|
96
|
-
|
|
97
|
+
globalThis.__dirname = dirname(fileURLToPath(import.meta.url));
|
|
97
98
|
|
|
98
99
|
const preload = join(__dirname, '../preload/index.mjs');
|
|
99
100
|
const url = process.env.VITE_DEV_SERVER_URL;
|
|
@@ -112,12 +113,22 @@ async function createWindow() {
|
|
|
112
113
|
|
|
113
114
|
if (isDev) {
|
|
114
115
|
win.loadURL(url);
|
|
115
|
-
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
116
118
|
win.loadFile(indexHtml);
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
|
|
120
122
|
app.whenReady().then(createWindow);
|
|
123
|
+
|
|
124
|
+
process.on('message', (data) => {
|
|
125
|
+
// When restarting the electron, if devTools is turned on, the electron may not be able to shut down normally.
|
|
126
|
+
if (data === ELECTRON_EXIT) {
|
|
127
|
+
if (win) {
|
|
128
|
+
win.webContents.closeDevTools();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
121
132
|
```
|
|
122
133
|
|
|
123
134
|
### vue
|
|
@@ -138,10 +149,11 @@ Electron `preload process` must use the `.mjs` suffix, otherwise an error will b
|
|
|
138
149
|
- `vite.config.ts`
|
|
139
150
|
|
|
140
151
|
```ts
|
|
141
|
-
import { defineConfig } from 'vite';
|
|
142
152
|
// import renderer from 'vite-plugin-electron-renderer'; // Enable nodeIntegration
|
|
143
153
|
import electron from '@tomjs/vite-plugin-electron';
|
|
144
154
|
import vue from '@vitejs/plugin-vue';
|
|
155
|
+
import { defineConfig } from 'vite';
|
|
156
|
+
|
|
145
157
|
export default defineConfig({
|
|
146
158
|
plugins: [
|
|
147
159
|
vue(),
|
|
@@ -177,9 +189,9 @@ Take using `cjs` as an example
|
|
|
177
189
|
- `vite.config.ts`
|
|
178
190
|
|
|
179
191
|
```ts
|
|
180
|
-
import { defineConfig } from 'vite';
|
|
181
192
|
import electron from '@tomjs/vite-plugin-electron';
|
|
182
193
|
import react from '@vitejs/plugin-react-swc';
|
|
194
|
+
import { defineConfig } from 'vite';
|
|
183
195
|
|
|
184
196
|
export default defineConfig({
|
|
185
197
|
plugins: [react(), electron()],
|
|
@@ -194,15 +206,15 @@ export default defineConfig({
|
|
|
194
206
|
|
|
195
207
|
### PluginOptions
|
|
196
208
|
|
|
197
|
-
| Property
|
|
198
|
-
|
|
|
199
|
-
| recommended | `boolean`
|
|
200
|
-
| external
|
|
201
|
-
| main
|
|
202
|
-
| preload
|
|
203
|
-
| debug
|
|
204
|
-
| builder
|
|
205
|
-
| inspect
|
|
209
|
+
| Property | Type | Default | Description |
|
|
210
|
+
| ----------- | ---------------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
211
|
+
| recommended | `boolean` | `true` | This option is intended to provide recommended default parameters and behavior. |
|
|
212
|
+
| external | `string[]` | | Don't bundle these modules, but dependencies and peerDependencies in your package.json are always excluded.[See more](https://tsdown.dev/reference/api/Interface.UserConfig#external) |
|
|
213
|
+
| main | [MainOptions](#MainOptions) | | Configuration options for the electron main process. |
|
|
214
|
+
| preload | [PreloadOptions](#PreloadOptions) | | Configuration options for the electron preload process. |
|
|
215
|
+
| debug | `boolean` | `false` | Electron debug mode, don't startup electron. You can also use `process.env.VITE_ELECTRON_DEBUG`. Default is false. |
|
|
216
|
+
| builder | `boolean` \| [BuilderOptions](#BuilderOptions) | `false` | If it is a `boolean` type, whether to enable [electron-builder](https://www.electron.build). If it is an object, it is the [configuration](https://www.electron.build/configuration/configuration) of [electron-builder](https://www.electron.build). You can also turn it on using `process.env.VITE_ELECTRON_DEBUG`. |
|
|
217
|
+
| inspect | `boolean` | `false` | Electron will listen for V8 inspector protocol messages on the specified port, an external debugger will need to connect on this port. You can also use `process.env.VITE_ELECTRON_INSPECT`. See [debugging-main-process](https://www.electronjs.org/docs/latest/tutorial/debugging-main-process) for more information. |
|
|
206
218
|
|
|
207
219
|
**Notice**
|
|
208
220
|
|
|
@@ -214,25 +226,26 @@ The `recommended` option is used to set the default configuration and behavior,
|
|
|
214
226
|
|
|
215
227
|
### MainOptions
|
|
216
228
|
|
|
217
|
-
Based on [Options](https://
|
|
229
|
+
Based on [Options](https://tsdown.dev/reference/api/Interface.UserConfig) of [tsdown](https://tsdown.dev), some default values are added for ease of use.
|
|
218
230
|
|
|
219
|
-
| Property
|
|
220
|
-
|
|
|
221
|
-
| entry
|
|
222
|
-
| format
|
|
223
|
-
| outDir
|
|
224
|
-
|
|
|
231
|
+
| Property | Type | Default | Description |
|
|
232
|
+
| ----------- | ----------------------------- | ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --- |
|
|
233
|
+
| entry | `string` | `-` | The main process entry file. |
|
|
234
|
+
| format | `'cjs' \| 'esm'` | `-` | The bundle format. If not specified, it will use the "type" field from package.json. |
|
|
235
|
+
| outDir | `string` | "dist-electron/main" | The output directory for the main process files |
|
|
236
|
+
| watchFiles | `string \| string[]` | `undefined` | Monitor Electron-related files or folders. If `recommended:true`, monitor the `electron/main` and `electron/preload` directories; otherwise, specify the corresponding Electron code directory. Failure to specify may cause Electron to restart indefinitely. | |
|
|
237
|
+
| ignoreWatch | `Arrayable<string \| RegExp>` | `'.history', '.temp', '.tmp', '.cache', 'dist'` | Ignore files or folders being watched |
|
|
225
238
|
|
|
226
239
|
### PreloadOptions
|
|
227
240
|
|
|
228
|
-
Based on [Options](https://
|
|
241
|
+
Based on [Options](https://tsdown.dev/reference/api/Interface.UserConfig) of [tsdown](https://tsdown.dev), some default values are added for ease of use.
|
|
229
242
|
|
|
230
|
-
| Property
|
|
231
|
-
|
|
|
232
|
-
| entry
|
|
233
|
-
| format
|
|
234
|
-
| outDir
|
|
235
|
-
| onSuccess | `() => Promise<void \| undefined \| (() => void \| Promise<void>)>` | `undefined`
|
|
243
|
+
| Property | Type | Default | Description |
|
|
244
|
+
| --------- | ------------------------------------------------------------------- | ----------------------- | ------------------------------------------------------------------------------------ |
|
|
245
|
+
| entry | `string` | `-` | The preload process entry file. |
|
|
246
|
+
| format | `'cjs' \| 'esm'` | `-` | The bundle format. If not specified, it will use the "type" field from package.json. |
|
|
247
|
+
| outDir | `string` | "dist-electron/preload" | The output directory for the preload process files |
|
|
248
|
+
| onSuccess | `() => Promise<void \| undefined \| (() => void \| Promise<void>)>` | `undefined` | A function that will be executed after the build succeeds. |
|
|
236
249
|
|
|
237
250
|
### BuilderOptions
|
|
238
251
|
|
|
@@ -245,11 +258,11 @@ _Not suitable for everyone._
|
|
|
245
258
|
|
|
246
259
|
To use this function, you need to install additional `electron-builder`
|
|
247
260
|
|
|
248
|
-
| Property
|
|
249
|
-
|
|
|
250
|
-
| appId
|
|
251
|
-
| productName
|
|
252
|
-
| builderConfig | [Configuration](https://www.electron.build/configuration/configuration#configurationF) | `undefined`
|
|
261
|
+
| Property | Type | Default | Description |
|
|
262
|
+
| ------------- | -------------------------------------------------------------------------------------- | ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
263
|
+
| appId | `string` | `"com.electron.${name}"` | The application id. [See More](https://www.electron.build/configuration/configuration#configuration) |
|
|
264
|
+
| productName | `string` | `"com.electron.${name}"` | product name.[See More](https://www.electron.build/configuration/configuration#configuration) |
|
|
265
|
+
| builderConfig | [Configuration](https://www.electron.build/configuration/configuration#configurationF) | `undefined` | [electron-builder](https://www.electron.build)'s [Configuration](https://www.electron.build/configuration/configuration#configuration) |
|
|
253
266
|
|
|
254
267
|
The default configuration is as follows:
|
|
255
268
|
|
|
@@ -303,11 +316,11 @@ const config = {
|
|
|
303
316
|
|
|
304
317
|
### Vite plugin variables
|
|
305
318
|
|
|
306
|
-
| Variable
|
|
307
|
-
|
|
|
308
|
-
| `VITE_ELECTRON_DEBUG`
|
|
319
|
+
| Variable | Description |
|
|
320
|
+
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
321
|
+
| `VITE_ELECTRON_DEBUG` | Electron main process debug, don't startup electron. When value is true or 1 to enable, false or 0 to disable.Default is undefined. |
|
|
309
322
|
| `VITE_ELECTRON_INSPECT` | Electron will listen for V8 inspector protocol messages on the specified port, an external debugger will need to connect on this port. When value is true, the default port is 5858. |
|
|
310
|
-
| `VITE_ELECTRON_BUILDER` | Enable [electron-builder](https://www.electron.build) to package. When value is true or 1 to enable, false or 0 to disable. Default is undefined.
|
|
323
|
+
| `VITE_ELECTRON_BUILDER` | Enable [electron-builder](https://www.electron.build) to package. When value is true or 1 to enable, false or 0 to disable. Default is undefined. |
|
|
311
324
|
|
|
312
325
|
### Application variables
|
|
313
326
|
|
|
@@ -332,13 +345,16 @@ app.whenReady().then(() => {
|
|
|
332
345
|
);
|
|
333
346
|
|
|
334
347
|
installExtension([REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS])
|
|
335
|
-
.then(exts => {
|
|
348
|
+
.then((exts) => {
|
|
349
|
+
// Install the extension before enabling the developer tools; otherwise, the extension may fail to load.
|
|
350
|
+
// win.webContents.openDevTools();
|
|
351
|
+
|
|
336
352
|
console.log(
|
|
337
353
|
'Added Extension: ',
|
|
338
354
|
exts.map(s => s.name),
|
|
339
355
|
);
|
|
340
356
|
})
|
|
341
|
-
.catch(err => {
|
|
357
|
+
.catch((err) => {
|
|
342
358
|
console.log('Failed to install extensions');
|
|
343
359
|
console.error(err);
|
|
344
360
|
});
|
package/README.zh_CN.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
## 特性
|
|
12
12
|
|
|
13
|
-
- 使用 [
|
|
13
|
+
- 使用 [tsdown](https://tsdown.dev) 快速构建 `main` 和 `preload`
|
|
14
14
|
- 配置简单,专注业务
|
|
15
15
|
- 支持 `main` 的 `热重启`
|
|
16
16
|
- 支持 `preload` 的 `热重载`
|
|
@@ -90,13 +90,15 @@ npm i electron-builder --save-dev
|
|
|
90
90
|
```ts
|
|
91
91
|
import { dirname } from 'node:path';
|
|
92
92
|
import { fileURLToPath } from 'node:url';
|
|
93
|
+
import { ELECTRON_EXIT } from '@tomjs/vite-plugin-electron/electron';
|
|
93
94
|
import { app, BrowserWindow } from 'electron';
|
|
94
95
|
|
|
95
96
|
// when package.json "type": module"
|
|
96
|
-
|
|
97
|
+
globalThis.__dirname = dirname(fileURLToPath(import.meta.url));
|
|
97
98
|
|
|
98
99
|
const preload = join(__dirname, '../preload/index.mjs');
|
|
99
100
|
const url = process.env.VITE_DEV_SERVER_URL;
|
|
101
|
+
let win: BrowserWindow | null = null;
|
|
100
102
|
|
|
101
103
|
async function createWindow() {
|
|
102
104
|
win = new BrowserWindow({
|
|
@@ -112,12 +114,22 @@ async function createWindow() {
|
|
|
112
114
|
|
|
113
115
|
if (isDev) {
|
|
114
116
|
win.loadURL(url);
|
|
115
|
-
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
116
119
|
win.loadFile(indexHtml);
|
|
117
120
|
}
|
|
118
121
|
}
|
|
119
122
|
|
|
120
123
|
app.whenReady().then(createWindow);
|
|
124
|
+
|
|
125
|
+
process.on('message', (data) => {
|
|
126
|
+
// 重启 electron 时,如果 devTools 打开可能会造成 electron 无法正常关闭
|
|
127
|
+
if (data === ELECTRON_EXIT) {
|
|
128
|
+
if (win) {
|
|
129
|
+
win.webContents.closeDevTools();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
121
133
|
```
|
|
122
134
|
|
|
123
135
|
### vue
|
|
@@ -138,10 +150,10 @@ Electron `preload process` 必须使用 `.mjs` 后缀,否则报错,查看[
|
|
|
138
150
|
- `vite.config.ts`
|
|
139
151
|
|
|
140
152
|
```ts
|
|
141
|
-
import { defineConfig } from 'vite';
|
|
142
153
|
// import renderer from 'vite-plugin-electron-renderer'; // 启用 nodeIntegration
|
|
143
154
|
import electron from '@tomjs/vite-plugin-electron';
|
|
144
155
|
import vue from '@vitejs/plugin-vue';
|
|
156
|
+
import { defineConfig } from 'vite';
|
|
145
157
|
|
|
146
158
|
export default defineConfig({
|
|
147
159
|
plugins: [
|
|
@@ -178,9 +190,9 @@ export default defineConfig({
|
|
|
178
190
|
- `vite.config.ts`
|
|
179
191
|
|
|
180
192
|
```ts
|
|
181
|
-
import { defineConfig } from 'vite';
|
|
182
193
|
import electron from '@tomjs/vite-plugin-electron';
|
|
183
194
|
import react from '@vitejs/plugin-react-swc';
|
|
195
|
+
import { defineConfig } from 'vite';
|
|
184
196
|
|
|
185
197
|
export default defineConfig({
|
|
186
198
|
plugins: [react(), electron()],
|
|
@@ -195,15 +207,15 @@ export default defineConfig({
|
|
|
195
207
|
|
|
196
208
|
### PluginOptions
|
|
197
209
|
|
|
198
|
-
| 参数名
|
|
199
|
-
|
|
|
200
|
-
| recommended | `boolean`
|
|
201
|
-
| external
|
|
202
|
-
| main
|
|
203
|
-
| preload
|
|
204
|
-
| debug
|
|
205
|
-
| builder
|
|
206
|
-
| inspect
|
|
210
|
+
| 参数名 | 类型 | 默认值 | 说明 |
|
|
211
|
+
| ----------- | --------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
212
|
+
| recommended | `boolean` | `true` | 这个选项是为了提供推荐的默认参数和行为 |
|
|
213
|
+
| external | `string[]` | | 不打包这些模块,但是 `dependencies` and `peerDependencies` 默认排除,[详见](https://tsdown.dev/zh-CN/reference/api/Interface.UserConfig) |
|
|
214
|
+
| main | [MainOptions](#MainOptions) | | electron main 进程选项 |
|
|
215
|
+
| preload | [PreloadOptions](#PreloadOptions) | | electron preload 进程选项 |
|
|
216
|
+
| debug | `boolean` | `false` | Electron调试模式,不启动Electron。 您还可以使用 `process.env.VITE_ELECTRON_DEBUG` |
|
|
217
|
+
| builder | `boolean` | `false` | 如果是`boolean`类型,是否启用[electron-builder](https://www.electron.build)。如果是`Object`,则是[electron-builder](https://www.electron.build)的[配置](https://www.electron.build/configuration/configuration)。 您还可以使用 `process.env.VITE_ELECTRON_DEBUG` 开启它。 |
|
|
218
|
+
| inspect | `boolean` | `false` | Electron 将监听指定 port 上的 V8 调试协议消息, 外部调试器需要连接到此端口上。您还可以使用 `process.env.VITE_ELECTRON_INSPECT`。 有关更多信息,请参阅[debugging-main-process](https://www.electronjs.org/zh/docs/latest/tutorial/debugging-main-process)。 |
|
|
207
219
|
|
|
208
220
|
`recommended` 选项用于设置默认配置和行为,几乎可以达到零配置使用,默认为 `true` 。如果你要自定义配置,请设置它为`false`。以下默认的前提条件是使用推荐的 [项目结构](#目录结构)。
|
|
209
221
|
|
|
@@ -213,25 +225,26 @@ export default defineConfig({
|
|
|
213
225
|
|
|
214
226
|
### MainOptions
|
|
215
227
|
|
|
216
|
-
继承自 [
|
|
228
|
+
继承自 [tsdown](https://tsdown.dev/) 的 [Options](https://tsdown.dev/zh-CN/reference/api/Interface.UserConfig),添加了一些默认值,方便使用。
|
|
217
229
|
|
|
218
|
-
| 参数名
|
|
219
|
-
|
|
|
220
|
-
| **entry**
|
|
221
|
-
| format
|
|
222
|
-
| outDir
|
|
223
|
-
|
|
|
230
|
+
| 参数名 | 类型 | 默认值 | 说明 |
|
|
231
|
+
| ----------- | ----------------------------- | ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
232
|
+
| **entry** | `string` | `-` | main 入口文件 |
|
|
233
|
+
| format | `'cjs' \| 'esm'` | `-` | 打包格式。如果未指定,将使用 package.json 中的 "type" 字段 |
|
|
234
|
+
| outDir | `string` | `"dist-electron/main"` | main 输出文件夹 |
|
|
235
|
+
| watchFiles | `string \| string[]` | `undefined` | 监听 electron 相关文件或文件夹,如果 `recommended:true`,则监听 `electron/main`、`electron/preload` 目录,否则需要指定 electron 代码对应目录,如果没有指定可能会造成 electron 无限重启 |
|
|
236
|
+
| ignoreWatch | `Arrayable<string \| RegExp>` | `'.history', '.temp', '.tmp', '.cache', 'dist'` | 忽略监听的文件或文件夹 |
|
|
224
237
|
|
|
225
238
|
### PreloadOptions
|
|
226
239
|
|
|
227
|
-
继承自 [
|
|
240
|
+
继承自 [tsdown](https://tsdown.dev) 的 [Options](https://tsdown.dev/zh-CN/reference/api/Interface.UserConfig),添加了一些默认值,方便使用。
|
|
228
241
|
|
|
229
|
-
| 参数名
|
|
230
|
-
|
|
|
231
|
-
| **entry** | `string`
|
|
232
|
-
| format
|
|
233
|
-
| outDir
|
|
234
|
-
| onSuccess | `() => Promise<void \| undefined \| (() => void \| Promise<void>)>` | `undefined`
|
|
242
|
+
| 参数名 | 类型 | 默认值 | 说明 |
|
|
243
|
+
| --------- | ------------------------------------------------------------------- | ------------------------- | ---------------------------------------------------------- |
|
|
244
|
+
| **entry** | `string` | `-` | preload 入口文件 |
|
|
245
|
+
| format | `'cjs' \| 'esm'` | `-` | 打包格式。如果未指定,将使用 package.json 中的 "type" 字段 |
|
|
246
|
+
| outDir | `string` | `"dist-electron/preload"` | preload 输出文件夹 |
|
|
247
|
+
| onSuccess | `() => Promise<void \| undefined \| (() => void \| Promise<void>)>` | `undefined` | 构建成功后运行的回调函数 |
|
|
235
248
|
|
|
236
249
|
### BuilderOptions
|
|
237
250
|
|
|
@@ -244,11 +257,11 @@ _不适合所有人使用。_
|
|
|
244
257
|
|
|
245
258
|
使用该功能,需要额外安装 `electron-builder`
|
|
246
259
|
|
|
247
|
-
| 参数名
|
|
248
|
-
|
|
|
249
|
-
| appId
|
|
250
|
-
| productName
|
|
251
|
-
| builderConfig | [Configuration](https://www.electron.build/configuration/configuration#configurationF) | `undefined`
|
|
260
|
+
| 参数名 | 类型 | 默认值 | 说明 |
|
|
261
|
+
| ------------- | -------------------------------------------------------------------------------------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
|
|
262
|
+
| appId | `string` | `"com.electron.${name}"` | 应用程序 ID。[详细](https://www.electron.build/configuration/configuration#configuration) |
|
|
263
|
+
| productName | `string` | `` | 应用程序名称。[详细](https://www.electron.build/configuration/configuration#configuration) |
|
|
264
|
+
| builderConfig | [Configuration](https://www.electron.build/configuration/configuration#configurationF) | `undefined` | [electron-builder](https://www.electron.build) 的 [Configuration](https://www.electron.build/configuration/configuration#configuration) |
|
|
252
265
|
|
|
253
266
|
默认配置如下
|
|
254
267
|
|
|
@@ -302,10 +315,10 @@ const config = {
|
|
|
302
315
|
|
|
303
316
|
### vite 插件变量
|
|
304
317
|
|
|
305
|
-
| 变量
|
|
306
|
-
|
|
|
307
|
-
| `VITE_ELECTRON_DEBUG`
|
|
308
|
-
| `VITE_ELECTRON_INSPECT` | Electron 将在指定端口上侦听 V8 检查器协议消息,外部调试器需要连接到该端口。 当值为 true 时,默认端口为 5858。
|
|
318
|
+
| 变量 | 描述 |
|
|
319
|
+
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
|
|
320
|
+
| `VITE_ELECTRON_DEBUG` | Electron主进程调试,不启动Electron。 当值为 true 或 1 时启用,为 false 或 0 时禁用。默认值未定义。 |
|
|
321
|
+
| `VITE_ELECTRON_INSPECT` | Electron 将在指定端口上侦听 V8 检查器协议消息,外部调试器需要连接到该端口。 当值为 true 时,默认端口为 5858。 |
|
|
309
322
|
| `VITE_ELECTRON_BUILDER` | 启用 [ Electron-builder ](https://www.electron.build) 进行打包。 当值为 true 或 1 时启用,为 false 或 0 时禁用。 默认值未定义。 |
|
|
310
323
|
|
|
311
324
|
### 应用变量
|
|
@@ -331,13 +344,16 @@ app.whenReady().then(() => {
|
|
|
331
344
|
);
|
|
332
345
|
|
|
333
346
|
installExtension([REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS])
|
|
334
|
-
.then(exts => {
|
|
347
|
+
.then((exts) => {
|
|
348
|
+
// 安装扩展后再开启开发者工具,否则可能会出现扩展加载失败问题
|
|
349
|
+
// win.webContents.openDevTools();
|
|
350
|
+
|
|
335
351
|
console.log(
|
|
336
352
|
'Added Extension: ',
|
|
337
353
|
exts.map(s => s.name),
|
|
338
354
|
);
|
|
339
355
|
})
|
|
340
|
-
.catch(err => {
|
|
356
|
+
.catch((err) => {
|
|
341
357
|
console.log('Failed to install extensions');
|
|
342
358
|
console.error(err);
|
|
343
359
|
});
|