@tomjs/vite-plugin-electron 1.3.5 → 1.3.7

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
@@ -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
 
@@ -260,7 +261,7 @@ app.whenReady().then(() => {
260
261
 
261
262
  Start code compilation through the following configuration or `ELECTRON_DEBUG=1 vite dev`
262
263
 
263
- - Enable by setting `APP_ELECTRON_DEBUG=1` in `.env` file
264
+ - Enable by setting `APP_ELECTRON_DEBUG=1` in `.env.development` file
264
265
  - `vite.config.js` configures `electron({ debug: true })` to be turned on
265
266
 
266
267
  #### VSCODE
@@ -288,7 +289,3 @@ Run `Debug Main Process` through `vscode` to debug the main thread. For debuggin
288
289
  ]
289
290
  }
290
291
  ```
291
-
292
- **Notice**
293
-
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 consider using `cjs` mode.
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` | electron调试模式,不启动electron |
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
 
@@ -259,7 +260,7 @@ app.whenReady().then(() => {
259
260
 
260
261
  通过如下配置或者 `ELECTRON_DEBUG=1 vite dev` 启动代码编译
261
262
 
262
- - 通过 `.env` 文件设置 `APP_ELECTRON_DEBUG=1` 开启
263
+ - 通过 `.env.development` 文件设置 `APP_ELECTRON_DEBUG=1` 开启
263
264
  - `vite.config.js` 配置 `electron({ debug: true })` 开启
264
265
 
265
266
  #### VSCODE
@@ -287,7 +288,3 @@ app.whenReady().then(() => {
287
288
  ]
288
289
  }
289
290
  ```
290
-
291
- **说明**
292
-
293
- `Electron v28` 虽然支持了 `esm`,但是 `VSCode Debug` sourcemap支持可能有问题,断点无法正常工作,这时可以考虑使用 `cjs` 模式
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
- process.electronApp = _child_process.spawn.call(void 0, _electron2.default, ["."], {
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)) {
@@ -170,6 +179,7 @@ function preMergeOptions(options) {
170
179
  format,
171
180
  clean: true,
172
181
  dts: false,
182
+ treeshake: !!isDev,
173
183
  outExtension({ format: format2 }) {
174
184
  return {
175
185
  js: format2 === "esm" ? ".mjs" : `.js`
@@ -208,9 +218,18 @@ function preMergeOptions(options) {
208
218
  });
209
219
  return opts;
210
220
  }
221
+ function geNumberBooleanValue(value) {
222
+ if (typeof value !== "string") {
223
+ return;
224
+ }
225
+ if (["true", "false"].includes(value)) {
226
+ return value === "true";
227
+ }
228
+ const v = Number(value);
229
+ return Number.isNaN(v) ? void 0 : v;
230
+ }
211
231
  function vitePluginElectron(options) {
212
232
  const opts = preMergeOptions(options);
213
- const isDev = process.env.NODE_ENV === "development";
214
233
  let isServer = false;
215
234
  return {
216
235
  name: PLUGIN_NAME,
@@ -253,6 +272,7 @@ function vitePluginElectron(options) {
253
272
  },
254
273
  configResolved(config) {
255
274
  opts.debug = config.env.APP_ELECTRON_DEBUG ? !!config.env.APP_ELECTRON_DEBUG : opts.debug;
275
+ opts.inspect = config.env.APP_ELECTRON_INSPECT ? geNumberBooleanValue(config.env.APP_ELECTRON_INSPECT) : opts.inspect;
256
276
  },
257
277
  configureServer(server) {
258
278
  if (!server || !server.httpServer) {
@@ -278,7 +298,6 @@ function vitePluginElectron(options) {
278
298
  const env = Object.keys(process.env).filter((s) => s.startsWith("APP_") || s.startsWith("VITE_")).map((s) => `${s}=${process.env[s]}`).join("\n");
279
299
  _fs.writeFileSync.call(void 0, _path2.default.join(DEBUG_PATH, ".env"), `NODE_ENV=development
280
300
  ${env}`);
281
- console.log("Server is running");
282
301
  await runServe(opts, server);
283
302
  });
284
303
  },
package/dist/index.mjs CHANGED
@@ -75,7 +75,15 @@ async function startup(options) {
75
75
  return;
76
76
  }
77
77
  await startup.exit();
78
- process.electronApp = spawn(electron, ["."], {
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)) {
@@ -169,6 +178,7 @@ function preMergeOptions(options) {
169
178
  format,
170
179
  clean: true,
171
180
  dts: false,
181
+ treeshake: !!isDev,
172
182
  outExtension({ format: format2 }) {
173
183
  return {
174
184
  js: format2 === "esm" ? ".mjs" : `.js`
@@ -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,
@@ -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) {
@@ -277,7 +297,6 @@ function vitePluginElectron(options) {
277
297
  const env = Object.keys(process.env).filter((s) => s.startsWith("APP_") || s.startsWith("VITE_")).map((s) => `${s}=${process.env[s]}`).join("\n");
278
298
  writeFileSync(path.join(DEBUG_PATH, ".env"), `NODE_ENV=development
279
299
  ${env}`);
280
- console.log("Server is running");
281
300
  await runServe(opts, server);
282
301
  });
283
302
  },
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomjs/vite-plugin-electron",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
4
4
  "description": "A simple vite plugin for electron, supports esm/cjs, support esm in electron v28+",
5
5
  "keywords": [
6
6
  "vite",