@tomjs/vite-plugin-electron 1.3.4 → 1.3.6
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 +10 -2
- package/README.zh_CN.md +10 -2
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +24 -4
- package/dist/index.mjs +24 -4
- package/env.d.ts +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -185,7 +185,8 @@ export default defineConfig({
|
|
|
185
185
|
| external | `string[]` | | Don't bundle these modules, but dependencies and peerDependencies in your package.json are always excluded.[See more](https://tsup.egoist.dev/#excluding-packages) |
|
|
186
186
|
| main | [MainOptions](#MainOptions) | | Configuration options for the electron main process. |
|
|
187
187
|
| preload | [PreloadOptions](#PreloadOptions) | | Configuration options for the electron preload process. |
|
|
188
|
-
| debug | `boolean` | `false` | Electron debug mode, don't startup electron. |
|
|
188
|
+
| debug | `boolean` | `false` | Electron debug mode, don't startup electron. You can also use `process.env.APP_ELECTRON_DEBUG`. Default is false. |
|
|
189
|
+
| 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.APP_ELECTRON_INSPECT`. See [debugging-main-process](https://www.electronjs.org/docs/latest/tutorial/debugging-main-process) for more information. |
|
|
189
190
|
|
|
190
191
|
**Notice**
|
|
191
192
|
|
|
@@ -291,4 +292,11 @@ Run `Debug Main Process` through `vscode` to debug the main thread. For debuggin
|
|
|
291
292
|
|
|
292
293
|
**Notice**
|
|
293
294
|
|
|
294
|
-
Although `Electron v28` supports `esm`, there may be problems with `VSCode Debug` sourcemap support and breakpoints cannot work properly. In this case, you can
|
|
295
|
+
Although `Electron v28` supports `esm`, there may be problems with `VSCode Debug` sourcemap support and breakpoints cannot work properly. In this case, you can use `cjs` mode or turn off `sourcemap`
|
|
296
|
+
|
|
297
|
+
```ts
|
|
298
|
+
electron({
|
|
299
|
+
main: { sourcemap: false },
|
|
300
|
+
preload: { sourcemap: false },
|
|
301
|
+
});
|
|
302
|
+
```
|
package/README.zh_CN.md
CHANGED
|
@@ -186,7 +186,8 @@ export default defineConfig({
|
|
|
186
186
|
| external | `string[]` | | 不打包这些模块,但是 `dependencies` and `peerDependencies` 默认排除,[详见](https://tsup.egoist.dev/#excluding-packages) |
|
|
187
187
|
| main | [MainOptions](#MainOptions) | | electron main 进程选项 |
|
|
188
188
|
| preload | [PreloadOptions](#PreloadOptions) | | electron preload 进程选项 |
|
|
189
|
-
| debug | `boolean` | `false` |
|
|
189
|
+
| debug | `boolean` | `false` | Electron调试模式,不启动Electron。 您还可以使用 `process.env.APP_ELECTRON_DEBUG` |
|
|
190
|
+
| inspect | `boolean` | `false` | Electron 将监听指定 port 上的 V8 调试协议消息, 外部调试器需要连接到此端口上。您还可以使用 `process.env.APP_ELECTRON_INSPECT`。 有关更多信息,请参阅[debugging-main-process](https://www.electronjs.org/zh/docs/latest/tutorial/debugging-main-process)。 |
|
|
190
191
|
|
|
191
192
|
`recommended` 选项用于设置默认配置和行为,几乎可以达到零配置使用,默认为 `true` 。如果你要自定义配置,请设置它为`false`。以下默认的前提条件是使用推荐的 [项目结构](#目录结构)。
|
|
192
193
|
|
|
@@ -290,4 +291,11 @@ app.whenReady().then(() => {
|
|
|
290
291
|
|
|
291
292
|
**说明**
|
|
292
293
|
|
|
293
|
-
`Electron v28` 虽然支持了 `esm`,但是 `VSCode Debug` sourcemap
|
|
294
|
+
`Electron v28` 虽然支持了 `esm`,但是 `VSCode Debug` sourcemap支持可能有问题,断点无法正常工作。这种情况可以使用 `cjs` 模式或关闭 `sourcemap`。
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
electron({
|
|
298
|
+
main: { sourcemap: false },
|
|
299
|
+
preload: { sourcemap: false },
|
|
300
|
+
});
|
|
301
|
+
```
|
package/dist/index.d.mts
CHANGED
|
@@ -79,6 +79,14 @@ interface PluginOptions {
|
|
|
79
79
|
* @default false
|
|
80
80
|
*/
|
|
81
81
|
debug?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Electron will listen for V8 inspector protocol messages on the specified port, an external debugger will need to connect on this port.
|
|
84
|
+
* You can also use `process.env.APP_ELECTRON_INSPECT`. See [debugging-main-process](https://www.electronjs.org/docs/latest/tutorial/debugging-main-process) for more information.
|
|
85
|
+
* The default port is false.
|
|
86
|
+
* @see https://www.electronjs.org/docs/latest/tutorial/debugging-main-process
|
|
87
|
+
* @default false
|
|
88
|
+
*/
|
|
89
|
+
inspect?: number | boolean;
|
|
82
90
|
}
|
|
83
91
|
|
|
84
92
|
declare function vitePluginElectron(options?: PluginOptions): Plugin;
|
package/dist/index.d.ts
CHANGED
|
@@ -79,6 +79,14 @@ interface PluginOptions {
|
|
|
79
79
|
* @default false
|
|
80
80
|
*/
|
|
81
81
|
debug?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Electron will listen for V8 inspector protocol messages on the specified port, an external debugger will need to connect on this port.
|
|
84
|
+
* You can also use `process.env.APP_ELECTRON_INSPECT`. See [debugging-main-process](https://www.electronjs.org/docs/latest/tutorial/debugging-main-process) for more information.
|
|
85
|
+
* The default port is false.
|
|
86
|
+
* @see https://www.electronjs.org/docs/latest/tutorial/debugging-main-process
|
|
87
|
+
* @default false
|
|
88
|
+
*/
|
|
89
|
+
inspect?: number | boolean;
|
|
82
90
|
}
|
|
83
91
|
|
|
84
92
|
declare function vitePluginElectron(options?: PluginOptions): Plugin;
|
package/dist/index.js
CHANGED
|
@@ -75,7 +75,15 @@ async function startup(options) {
|
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
77
|
await startup.exit();
|
|
78
|
-
|
|
78
|
+
const args = ["."];
|
|
79
|
+
if (options.inspect) {
|
|
80
|
+
if (typeof options.inspect === "number") {
|
|
81
|
+
args.push(`--inspect=${options.inspect}`);
|
|
82
|
+
} else {
|
|
83
|
+
args.push(`--inspect`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
process.electronApp = _child_process.spawn.call(void 0, _electron2.default, args, {
|
|
79
87
|
stdio: "inherit"
|
|
80
88
|
});
|
|
81
89
|
process.electronApp.once("exit", process.exit);
|
|
@@ -151,6 +159,7 @@ function readJson(path2) {
|
|
|
151
159
|
}
|
|
152
160
|
|
|
153
161
|
// src/index.ts
|
|
162
|
+
var isDev = process.env.NODE_ENV === "development";
|
|
154
163
|
function getPkg() {
|
|
155
164
|
const pkgFile = _path2.default.resolve(process.cwd(), "package.json");
|
|
156
165
|
if (!_fs2.default.existsSync(pkgFile)) {
|
|
@@ -166,6 +175,7 @@ function preMergeOptions(options) {
|
|
|
166
175
|
const pkg = getPkg();
|
|
167
176
|
const format = pkg.type === "module" ? "esm" : "cjs";
|
|
168
177
|
const electron2 = {
|
|
178
|
+
target: ["es2021", "node16"],
|
|
169
179
|
format,
|
|
170
180
|
clean: true,
|
|
171
181
|
dts: false,
|
|
@@ -207,9 +217,18 @@ function preMergeOptions(options) {
|
|
|
207
217
|
});
|
|
208
218
|
return opts;
|
|
209
219
|
}
|
|
220
|
+
function geNumberBooleanValue(value) {
|
|
221
|
+
if (typeof value !== "string") {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (["true", "false"].includes(value)) {
|
|
225
|
+
return value === "true";
|
|
226
|
+
}
|
|
227
|
+
const v = Number(value);
|
|
228
|
+
return Number.isNaN(v) ? void 0 : v;
|
|
229
|
+
}
|
|
210
230
|
function vitePluginElectron(options) {
|
|
211
231
|
const opts = preMergeOptions(options);
|
|
212
|
-
const isDev = process.env.NODE_ENV === "development";
|
|
213
232
|
let isServer = false;
|
|
214
233
|
return {
|
|
215
234
|
name: PLUGIN_NAME,
|
|
@@ -228,8 +247,8 @@ function vitePluginElectron(options) {
|
|
|
228
247
|
opts.preload.outDir ||= _path2.default.join("dist-electron", "preload");
|
|
229
248
|
}
|
|
230
249
|
if (isDev) {
|
|
231
|
-
opts.main.sourcemap ??=
|
|
232
|
-
opts.preload.sourcemap ??=
|
|
250
|
+
opts.main.sourcemap ??= true;
|
|
251
|
+
opts.preload.sourcemap ??= true;
|
|
233
252
|
} else {
|
|
234
253
|
opts.main.minify ??= true;
|
|
235
254
|
opts.preload.minify ??= true;
|
|
@@ -252,6 +271,7 @@ function vitePluginElectron(options) {
|
|
|
252
271
|
},
|
|
253
272
|
configResolved(config) {
|
|
254
273
|
opts.debug = config.env.APP_ELECTRON_DEBUG ? !!config.env.APP_ELECTRON_DEBUG : opts.debug;
|
|
274
|
+
opts.inspect = config.env.APP_ELECTRON_INSPECT ? geNumberBooleanValue(config.env.APP_ELECTRON_INSPECT) : opts.inspect;
|
|
255
275
|
},
|
|
256
276
|
configureServer(server) {
|
|
257
277
|
if (!server || !server.httpServer) {
|
package/dist/index.mjs
CHANGED
|
@@ -75,7 +75,15 @@ async function startup(options) {
|
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
77
|
await startup.exit();
|
|
78
|
-
|
|
78
|
+
const args = ["."];
|
|
79
|
+
if (options.inspect) {
|
|
80
|
+
if (typeof options.inspect === "number") {
|
|
81
|
+
args.push(`--inspect=${options.inspect}`);
|
|
82
|
+
} else {
|
|
83
|
+
args.push(`--inspect`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
process.electronApp = spawn(electron, args, {
|
|
79
87
|
stdio: "inherit"
|
|
80
88
|
});
|
|
81
89
|
process.electronApp.once("exit", process.exit);
|
|
@@ -150,6 +158,7 @@ function readJson(path2) {
|
|
|
150
158
|
}
|
|
151
159
|
|
|
152
160
|
// src/index.ts
|
|
161
|
+
var isDev = process.env.NODE_ENV === "development";
|
|
153
162
|
function getPkg() {
|
|
154
163
|
const pkgFile = path.resolve(process.cwd(), "package.json");
|
|
155
164
|
if (!fs2.existsSync(pkgFile)) {
|
|
@@ -165,6 +174,7 @@ function preMergeOptions(options) {
|
|
|
165
174
|
const pkg = getPkg();
|
|
166
175
|
const format = pkg.type === "module" ? "esm" : "cjs";
|
|
167
176
|
const electron2 = {
|
|
177
|
+
target: ["es2021", "node16"],
|
|
168
178
|
format,
|
|
169
179
|
clean: true,
|
|
170
180
|
dts: false,
|
|
@@ -206,9 +216,18 @@ function preMergeOptions(options) {
|
|
|
206
216
|
});
|
|
207
217
|
return opts;
|
|
208
218
|
}
|
|
219
|
+
function geNumberBooleanValue(value) {
|
|
220
|
+
if (typeof value !== "string") {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (["true", "false"].includes(value)) {
|
|
224
|
+
return value === "true";
|
|
225
|
+
}
|
|
226
|
+
const v = Number(value);
|
|
227
|
+
return Number.isNaN(v) ? void 0 : v;
|
|
228
|
+
}
|
|
209
229
|
function vitePluginElectron(options) {
|
|
210
230
|
const opts = preMergeOptions(options);
|
|
211
|
-
const isDev = process.env.NODE_ENV === "development";
|
|
212
231
|
let isServer = false;
|
|
213
232
|
return {
|
|
214
233
|
name: PLUGIN_NAME,
|
|
@@ -227,8 +246,8 @@ function vitePluginElectron(options) {
|
|
|
227
246
|
opts.preload.outDir ||= path.join("dist-electron", "preload");
|
|
228
247
|
}
|
|
229
248
|
if (isDev) {
|
|
230
|
-
opts.main.sourcemap ??=
|
|
231
|
-
opts.preload.sourcemap ??=
|
|
249
|
+
opts.main.sourcemap ??= true;
|
|
250
|
+
opts.preload.sourcemap ??= true;
|
|
232
251
|
} else {
|
|
233
252
|
opts.main.minify ??= true;
|
|
234
253
|
opts.preload.minify ??= true;
|
|
@@ -251,6 +270,7 @@ function vitePluginElectron(options) {
|
|
|
251
270
|
},
|
|
252
271
|
configResolved(config) {
|
|
253
272
|
opts.debug = config.env.APP_ELECTRON_DEBUG ? !!config.env.APP_ELECTRON_DEBUG : opts.debug;
|
|
273
|
+
opts.inspect = config.env.APP_ELECTRON_INSPECT ? geNumberBooleanValue(config.env.APP_ELECTRON_INSPECT) : opts.inspect;
|
|
254
274
|
},
|
|
255
275
|
configureServer(server) {
|
|
256
276
|
if (!server || !server.httpServer) {
|
package/env.d.ts
CHANGED
|
@@ -17,5 +17,9 @@ declare namespace NodeJS {
|
|
|
17
17
|
* Electron main process debug, don't startup electron
|
|
18
18
|
*/
|
|
19
19
|
APP_ELECTRON_DEBUG?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Electron will listen for V8 inspector protocol messages on the specified port, an external debugger will need to connect on this port. The default port is 5858.
|
|
22
|
+
*/
|
|
23
|
+
APP_ELECTRON_INSPECT?: string;
|
|
20
24
|
}
|
|
21
25
|
}
|