@tomjs/vite-plugin-electron 1.9.2 → 1.11.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 CHANGED
@@ -93,7 +93,7 @@ import { fileURLToPath } from 'node:url';
93
93
  import { app, BrowserWindow } from 'electron';
94
94
 
95
95
  // when package.json "type": module"
96
- global.__dirname = dirname(fileURLToPath(import.meta.url));
96
+ globalThis.__dirname = dirname(fileURLToPath(import.meta.url));
97
97
 
98
98
  const preload = join(__dirname, '../preload/index.mjs');
99
99
  const url = process.env.VITE_DEV_SERVER_URL;
@@ -112,7 +112,8 @@ async function createWindow() {
112
112
 
113
113
  if (isDev) {
114
114
  win.loadURL(url);
115
- } else {
115
+ }
116
+ else {
116
117
  win.loadFile(indexHtml);
117
118
  }
118
119
  }
@@ -138,10 +139,10 @@ Electron `preload process` must use the `.mjs` suffix, otherwise an error will b
138
139
  - `vite.config.ts`
139
140
 
140
141
  ```ts
141
- import { defineConfig } from 'vite';
142
142
  // import renderer from 'vite-plugin-electron-renderer'; // Enable nodeIntegration
143
143
  import electron from '@tomjs/vite-plugin-electron';
144
144
  import vue from '@vitejs/plugin-vue';
145
+ import { defineConfig } from 'vite';
145
146
  export default defineConfig({
146
147
  plugins: [
147
148
  vue(),
@@ -177,9 +178,9 @@ Take using `cjs` as an example
177
178
  - `vite.config.ts`
178
179
 
179
180
  ```ts
180
- import { defineConfig } from 'vite';
181
181
  import electron from '@tomjs/vite-plugin-electron';
182
182
  import react from '@vitejs/plugin-react-swc';
183
+ import { defineConfig } from 'vite';
183
184
 
184
185
  export default defineConfig({
185
186
  plugins: [react(), electron()],
@@ -194,15 +195,15 @@ export default defineConfig({
194
195
 
195
196
  ### PluginOptions
196
197
 
197
- | Property | Type | Default | Description |
198
- | --- | --- | --- | --- |
199
- | recommended | `boolean` | `true` | This option is intended to provide recommended default parameters and behavior. |
200
- | 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) |
201
- | main | [MainOptions](#MainOptions) | | Configuration options for the electron main process. |
202
- | preload | [PreloadOptions](#PreloadOptions) | | Configuration options for the electron preload process. |
203
- | debug | `boolean` | `false` | Electron debug mode, don't startup electron. You can also use `process.env.VITE_ELECTRON_DEBUG`. Default is false. |
204
- | 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`. |
205
- | 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. |
198
+ | Property | Type | Default | Description |
199
+ | ----------- | ---------------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
200
+ | recommended | `boolean` | `true` | This option is intended to provide recommended default parameters and behavior. |
201
+ | 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) |
202
+ | main | [MainOptions](#MainOptions) | | Configuration options for the electron main process. |
203
+ | preload | [PreloadOptions](#PreloadOptions) | | Configuration options for the electron preload process. |
204
+ | debug | `boolean` | `false` | Electron debug mode, don't startup electron. You can also use `process.env.VITE_ELECTRON_DEBUG`. Default is false. |
205
+ | 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`. |
206
+ | 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
207
 
207
208
  **Notice**
208
209
 
@@ -216,23 +217,23 @@ The `recommended` option is used to set the default configuration and behavior,
216
217
 
217
218
  Based on [Options](https://www.jsdocs.io/package/tsup) of [tsup](https://tsup.egoist.dev/), some default values are added for ease of use.
218
219
 
219
- | Property | Type | Default | Description |
220
- | --- | --- | --- | --- |
221
- | entry | `string` | `-` | The main process entry file. |
222
- | format | `'cjs' \| 'esm'` | `-` | The bundle format. If not specified, it will use the "type" field from package.json. |
223
- | outDir | `string` | "dist-electron/main" | The output directory for the main process files |
224
- | onSuccess | `() => Promise<void \| undefined \| (() => void \| Promise<void>)>` | `undefined` | A function that will be executed after the build succeeds. |
220
+ | Property | Type | Default | Description |
221
+ | --------- | ------------------------------------------------------------------- | -------------------- | ------------------------------------------------------------------------------------ |
222
+ | entry | `string` | `-` | The main process entry file. |
223
+ | format | `'cjs' \| 'esm'` | `-` | The bundle format. If not specified, it will use the "type" field from package.json. |
224
+ | outDir | `string` | "dist-electron/main" | The output directory for the main process files |
225
+ | onSuccess | `() => Promise<void \| undefined \| (() => void \| Promise<void>)>` | `undefined` | A function that will be executed after the build succeeds. |
225
226
 
226
227
  ### PreloadOptions
227
228
 
228
229
  Based on [Options](https://www.jsdocs.io/package/tsup) of [tsup](https://tsup.egoist.dev/), some default values are added for ease of use.
229
230
 
230
- | Property | Type | Default | Description |
231
- | --- | --- | --- | --- |
232
- | entry | `string` | `-` | The preload process entry file. |
233
- | format | `'cjs' \| 'esm'` | `-` | The bundle format. If not specified, it will use the "type" field from package.json. |
234
- | outDir | `string` | "dist-electron/preload" | The output directory for the preload process files |
235
- | onSuccess | `() => Promise<void \| undefined \| (() => void \| Promise<void>)>` | `undefined` | A function that will be executed after the build succeeds. |
231
+ | Property | Type | Default | Description |
232
+ | --------- | ------------------------------------------------------------------- | ----------------------- | ------------------------------------------------------------------------------------ |
233
+ | entry | `string` | `-` | The preload 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/preload" | The output directory for the preload process files |
236
+ | onSuccess | `() => Promise<void \| undefined \| (() => void \| Promise<void>)>` | `undefined` | A function that will be executed after the build succeeds. |
236
237
 
237
238
  ### BuilderOptions
238
239
 
@@ -245,11 +246,11 @@ _Not suitable for everyone._
245
246
 
246
247
  To use this function, you need to install additional `electron-builder`
247
248
 
248
- | Property | Type | Default | Description |
249
- | --- | --- | --- | --- |
250
- | appId | `string` | `"com.electron.${name}"` | The application id. [See More](https://www.electron.build/configuration/configuration#configuration) |
251
- | productName | `string` | `"com.electron.${name}"` | product name.[See More](https://www.electron.build/configuration/configuration#configuration) |
252
- | 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) |
249
+ | Property | Type | Default | Description |
250
+ | ------------- | -------------------------------------------------------------------------------------- | ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
251
+ | appId | `string` | `"com.electron.${name}"` | The application id. [See More](https://www.electron.build/configuration/configuration#configuration) |
252
+ | productName | `string` | `"com.electron.${name}"` | product name.[See More](https://www.electron.build/configuration/configuration#configuration) |
253
+ | 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
254
 
254
255
  The default configuration is as follows:
255
256
 
@@ -303,11 +304,11 @@ const config = {
303
304
 
304
305
  ### Vite plugin variables
305
306
 
306
- | Variable | Description |
307
- | --- | --- |
308
- | `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. |
307
+ | Variable | Description |
308
+ | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
309
+ | `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
310
  | `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. |
311
+ | `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
312
 
312
313
  ### Application variables
313
314
 
@@ -332,13 +333,13 @@ app.whenReady().then(() => {
332
333
  );
333
334
 
334
335
  installExtension([REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS])
335
- .then(exts => {
336
+ .then((exts) => {
336
337
  console.log(
337
338
  'Added Extension: ',
338
339
  exts.map(s => s.name),
339
340
  );
340
341
  })
341
- .catch(err => {
342
+ .catch((err) => {
342
343
  console.log('Failed to install extensions');
343
344
  console.error(err);
344
345
  });
package/README.zh_CN.md CHANGED
@@ -93,7 +93,7 @@ import { fileURLToPath } from 'node:url';
93
93
  import { app, BrowserWindow } from 'electron';
94
94
 
95
95
  // when package.json "type": module"
96
- global.__dirname = dirname(fileURLToPath(import.meta.url));
96
+ globalThis.__dirname = dirname(fileURLToPath(import.meta.url));
97
97
 
98
98
  const preload = join(__dirname, '../preload/index.mjs');
99
99
  const url = process.env.VITE_DEV_SERVER_URL;
@@ -112,7 +112,8 @@ async function createWindow() {
112
112
 
113
113
  if (isDev) {
114
114
  win.loadURL(url);
115
- } else {
115
+ }
116
+ else {
116
117
  win.loadFile(indexHtml);
117
118
  }
118
119
  }
@@ -138,10 +139,10 @@ Electron `preload process` 必须使用 `.mjs` 后缀,否则报错,查看[
138
139
  - `vite.config.ts`
139
140
 
140
141
  ```ts
141
- import { defineConfig } from 'vite';
142
142
  // import renderer from 'vite-plugin-electron-renderer'; // 启用 nodeIntegration
143
143
  import electron from '@tomjs/vite-plugin-electron';
144
144
  import vue from '@vitejs/plugin-vue';
145
+ import { defineConfig } from 'vite';
145
146
 
146
147
  export default defineConfig({
147
148
  plugins: [
@@ -178,9 +179,9 @@ export default defineConfig({
178
179
  - `vite.config.ts`
179
180
 
180
181
  ```ts
181
- import { defineConfig } from 'vite';
182
182
  import electron from '@tomjs/vite-plugin-electron';
183
183
  import react from '@vitejs/plugin-react-swc';
184
+ import { defineConfig } from 'vite';
184
185
 
185
186
  export default defineConfig({
186
187
  plugins: [react(), electron()],
@@ -195,15 +196,15 @@ export default defineConfig({
195
196
 
196
197
  ### PluginOptions
197
198
 
198
- | 参数名 | 类型 | 默认值 | 说明 |
199
- | --- | --- | --- | --- |
200
- | recommended | `boolean` | `true` | 这个选项是为了提供推荐的默认参数和行为 |
201
- | external | `string[]` | | 不打包这些模块,但是 `dependencies` and `peerDependencies` 默认排除,[详见](https://tsup.egoist.dev/#excluding-packages) |
202
- | main | [MainOptions](#MainOptions) | | electron main 进程选项 |
203
- | preload | [PreloadOptions](#PreloadOptions) | | electron preload 进程选项 |
204
- | debug | `boolean` | `false` | Electron调试模式,不启动Electron。 您还可以使用 `process.env.VITE_ELECTRON_DEBUG` |
205
- | 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` 开启它。 |
206
- | 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)。 |
199
+ | 参数名 | 类型 | 默认值 | 说明 |
200
+ | ----------- | --------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
201
+ | recommended | `boolean` | `true` | 这个选项是为了提供推荐的默认参数和行为 |
202
+ | external | `string[]` | | 不打包这些模块,但是 `dependencies` and `peerDependencies` 默认排除,[详见](https://tsup.egoist.dev/#excluding-packages) |
203
+ | main | [MainOptions](#MainOptions) | | electron main 进程选项 |
204
+ | preload | [PreloadOptions](#PreloadOptions) | | electron preload 进程选项 |
205
+ | debug | `boolean` | `false` | Electron调试模式,不启动Electron。 您还可以使用 `process.env.VITE_ELECTRON_DEBUG` |
206
+ | 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` 开启它。 |
207
+ | 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
208
 
208
209
  `recommended` 选项用于设置默认配置和行为,几乎可以达到零配置使用,默认为 `true` 。如果你要自定义配置,请设置它为`false`。以下默认的前提条件是使用推荐的 [项目结构](#目录结构)。
209
210
 
@@ -215,23 +216,23 @@ export default defineConfig({
215
216
 
216
217
  继承自 [tsup](https://tsup.egoist.dev/) 的 [Options](https://www.jsdocs.io/package/tsup),添加了一些默认值,方便使用。
217
218
 
218
- | 参数名 | 类型 | 默认值 | 说明 |
219
- | --- | --- | --- | --- |
220
- | **entry** | `string` | `-` | main 入口文件 |
221
- | format | `'cjs' \| 'esm'` | `-` | 打包格式。如果未指定,将使用 package.json 中的 "type" 字段 |
222
- | outDir | `string` | `"dist-electron/main"` | main 输出文件夹 |
223
- | onSuccess | `() => Promise<void \| undefined \| (() => void \| Promise<void>)>` | `undefined` | 构建成功后运行的回调函数 |
219
+ | 参数名 | 类型 | 默认值 | 说明 |
220
+ | --------- | ------------------------------------------------------------------- | ---------------------- | ---------------------------------------------------------- |
221
+ | **entry** | `string` | `-` | main 入口文件 |
222
+ | format | `'cjs' \| 'esm'` | `-` | 打包格式。如果未指定,将使用 package.json 中的 "type" 字段 |
223
+ | outDir | `string` | `"dist-electron/main"` | main 输出文件夹 |
224
+ | onSuccess | `() => Promise<void \| undefined \| (() => void \| Promise<void>)>` | `undefined` | 构建成功后运行的回调函数 |
224
225
 
225
226
  ### PreloadOptions
226
227
 
227
228
  继承自 [tsup](https://tsup.egoist.dev/) 的 [Options](https://www.jsdocs.io/package/tsup),添加了一些默认值,方便使用。
228
229
 
229
- | 参数名 | 类型 | 默认值 | 说明 |
230
- | --- | --- | --- | --- |
231
- | **entry** | `string` | `-` | preload 入口文件 |
232
- | format | `'cjs' \| 'esm'` | `-` | 打包格式。如果未指定,将使用 package.json 中的 "type" 字段 |
233
- | outDir | `string` | `"dist-electron/preload"` | preload 输出文件夹 |
234
- | onSuccess | `() => Promise<void \| undefined \| (() => void \| Promise<void>)>` | `undefined` | 构建成功后运行的回调函数 |
230
+ | 参数名 | 类型 | 默认值 | 说明 |
231
+ | --------- | ------------------------------------------------------------------- | ------------------------- | ---------------------------------------------------------- |
232
+ | **entry** | `string` | `-` | preload 入口文件 |
233
+ | format | `'cjs' \| 'esm'` | `-` | 打包格式。如果未指定,将使用 package.json 中的 "type" 字段 |
234
+ | outDir | `string` | `"dist-electron/preload"` | preload 输出文件夹 |
235
+ | onSuccess | `() => Promise<void \| undefined \| (() => void \| Promise<void>)>` | `undefined` | 构建成功后运行的回调函数 |
235
236
 
236
237
  ### BuilderOptions
237
238
 
@@ -244,11 +245,11 @@ _不适合所有人使用。_
244
245
 
245
246
  使用该功能,需要额外安装 `electron-builder`
246
247
 
247
- | 参数名 | 类型 | 默认值 | 说明 |
248
- | --- | --- | --- | --- |
249
- | appId | `string` | `"com.electron.${name}"` | 应用程序 ID。[详细](https://www.electron.build/configuration/configuration#configuration) |
250
- | productName | `string` | `` | 应用程序名称。[详细](https://www.electron.build/configuration/configuration#configuration) |
251
- | builderConfig | [Configuration](https://www.electron.build/configuration/configuration#configurationF) | `undefined` | [electron-builder](https://www.electron.build) 的 [Configuration](https://www.electron.build/configuration/configuration#configuration) |
248
+ | 参数名 | 类型 | 默认值 | 说明 |
249
+ | ------------- | -------------------------------------------------------------------------------------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
250
+ | appId | `string` | `"com.electron.${name}"` | 应用程序 ID。[详细](https://www.electron.build/configuration/configuration#configuration) |
251
+ | productName | `string` | `` | 应用程序名称。[详细](https://www.electron.build/configuration/configuration#configuration) |
252
+ | 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
253
 
253
254
  默认配置如下
254
255
 
@@ -302,10 +303,10 @@ const config = {
302
303
 
303
304
  ### vite 插件变量
304
305
 
305
- | 变量 | 描述 |
306
- | --- | --- |
307
- | `VITE_ELECTRON_DEBUG` | Electron主进程调试,不要启动Electron。 当值为 true 或 1 时启用,为 false 或 0 时禁用。默认值未定义。 |
308
- | `VITE_ELECTRON_INSPECT` | Electron 将在指定端口上侦听 V8 检查器协议消息,外部调试器需要连接到该端口。 当值为 true 时,默认端口为 5858。 |
306
+ | 变量 | 描述 |
307
+ | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
308
+ | `VITE_ELECTRON_DEBUG` | Electron主进程调试,不要启动Electron。 当值为 true 或 1 时启用,为 false 或 0 时禁用。默认值未定义。 |
309
+ | `VITE_ELECTRON_INSPECT` | Electron 将在指定端口上侦听 V8 检查器协议消息,外部调试器需要连接到该端口。 当值为 true 时,默认端口为 5858。 |
309
310
  | `VITE_ELECTRON_BUILDER` | 启用 [ Electron-builder ](https://www.electron.build) 进行打包。 当值为 true 或 1 时启用,为 false 或 0 时禁用。 默认值未定义。 |
310
311
 
311
312
  ### 应用变量
@@ -331,13 +332,13 @@ app.whenReady().then(() => {
331
332
  );
332
333
 
333
334
  installExtension([REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS])
334
- .then(exts => {
335
+ .then((exts) => {
335
336
  console.log(
336
337
  'Added Extension: ',
337
338
  exts.map(s => s.name),
338
339
  );
339
340
  })
340
- .catch(err => {
341
+ .catch((err) => {
341
342
  console.log('Failed to install extensions');
342
343
  console.error(err);
343
344
  });
package/dist/index.d.mts CHANGED
@@ -53,8 +53,8 @@ interface PreloadOptions extends Omit<Options, 'entry' | 'format' | 'outDir' | '
53
53
  /**
54
54
  * When `recommended` and `builder.enable` are both `true`, use [electron-builder](https://www.electron.build) to package Electron applications.
55
55
  *
56
- * * In the `build.outDir` directory configured in vite, generate a new package.json based on the configuration and package.json, excluding non-dependencies.
57
- * * Execute `npm install` and then package.
56
+ * In the `build.outDir` directory configured in vite, generate a new package.json based on the configuration and package.json, excluding non-dependencies.
57
+ * Execute `npm install` and then package.
58
58
  */
59
59
  interface BuilderOptions {
60
60
  /**
@@ -86,7 +86,7 @@ interface PluginOptions {
86
86
  /**
87
87
  * Recommended switch. Default is true.
88
88
  * if true, will have the following default behavior:
89
- * * will change the main/preload/renderer outDir to be parallel outDir;
89
+ * will change the main/preload/renderer outDir to be parallel outDir;
90
90
  * eg. if vite build.outDir is 'dist', will change main/preload/render to 'dist/main' and 'dist/preload' and 'dist/renderer'
91
91
  * @default true
92
92
  */
@@ -107,8 +107,8 @@ interface PluginOptions {
107
107
  /**
108
108
  * When `recommended` and `builder.enable` are both `true`, use [electron-builder](https://www.electron.build) to package Electron applications.
109
109
  *
110
- * * In the `build.outDir` directory configured in vite, generate a new package.json based on the configuration and package.json, excluding non-dependencies.
111
- * * Execute `npm install` and then package.
110
+ * In the `build.outDir` directory configured in vite, generate a new package.json based on the configuration and package.json, excluding non-dependencies.
111
+ * Execute `npm install` and then package.
112
112
  */
113
113
  builder?: boolean | BuilderOptions;
114
114
  /**
@@ -132,4 +132,4 @@ interface PluginOptions {
132
132
  */
133
133
  declare function useElectronPlugin(options?: PluginOptions): Plugin;
134
134
 
135
- export { BuilderOptions, MainOptions, PluginOptions, PreloadOptions, useElectronPlugin as default, useElectronPlugin };
135
+ export { type BuilderOptions, type MainOptions, type PluginOptions, type PreloadOptions, useElectronPlugin as default, useElectronPlugin };
package/dist/index.d.ts CHANGED
@@ -53,8 +53,8 @@ interface PreloadOptions extends Omit<Options, 'entry' | 'format' | 'outDir' | '
53
53
  /**
54
54
  * When `recommended` and `builder.enable` are both `true`, use [electron-builder](https://www.electron.build) to package Electron applications.
55
55
  *
56
- * * In the `build.outDir` directory configured in vite, generate a new package.json based on the configuration and package.json, excluding non-dependencies.
57
- * * Execute `npm install` and then package.
56
+ * In the `build.outDir` directory configured in vite, generate a new package.json based on the configuration and package.json, excluding non-dependencies.
57
+ * Execute `npm install` and then package.
58
58
  */
59
59
  interface BuilderOptions {
60
60
  /**
@@ -86,7 +86,7 @@ interface PluginOptions {
86
86
  /**
87
87
  * Recommended switch. Default is true.
88
88
  * if true, will have the following default behavior:
89
- * * will change the main/preload/renderer outDir to be parallel outDir;
89
+ * will change the main/preload/renderer outDir to be parallel outDir;
90
90
  * eg. if vite build.outDir is 'dist', will change main/preload/render to 'dist/main' and 'dist/preload' and 'dist/renderer'
91
91
  * @default true
92
92
  */
@@ -107,8 +107,8 @@ interface PluginOptions {
107
107
  /**
108
108
  * When `recommended` and `builder.enable` are both `true`, use [electron-builder](https://www.electron.build) to package Electron applications.
109
109
  *
110
- * * In the `build.outDir` directory configured in vite, generate a new package.json based on the configuration and package.json, excluding non-dependencies.
111
- * * Execute `npm install` and then package.
110
+ * In the `build.outDir` directory configured in vite, generate a new package.json based on the configuration and package.json, excluding non-dependencies.
111
+ * Execute `npm install` and then package.
112
112
  */
113
113
  builder?: boolean | BuilderOptions;
114
114
  /**
@@ -132,4 +132,4 @@ interface PluginOptions {
132
132
  */
133
133
  declare function useElectronPlugin(options?: PluginOptions): Plugin;
134
134
 
135
- export { BuilderOptions, MainOptions, PluginOptions, PreloadOptions, useElectronPlugin as default, useElectronPlugin };
135
+ export { type BuilderOptions, type MainOptions, type PluginOptions, type PreloadOptions, useElectronPlugin as default, useElectronPlugin };
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/index.ts
2
2
  var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
3
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
3
4
  var _lodashclonedeep = require('lodash.clonedeep'); var _lodashclonedeep2 = _interopRequireDefault(_lodashclonedeep);
4
5
  var _lodashmerge = require('lodash.merge'); var _lodashmerge2 = _interopRequireDefault(_lodashmerge);
5
- var _path = require('path'); var _path2 = _interopRequireDefault(_path);
6
6
 
7
7
  // src/builder.ts
8
8
  var _os = require('os'); var _os2 = _interopRequireDefault(_os);
@@ -54,9 +54,9 @@ var Logger = class {
54
54
  console.log(`${this.getTime()}${_kolorist.green.call(void 0, this.tag)}`, msg, ...rest);
55
55
  }
56
56
  };
57
- var createLogger = (tag) => {
57
+ function createLogger(tag) {
58
58
  return new Logger(tag || PLUGIN_NAME, true);
59
- };
59
+ }
60
60
 
61
61
  // src/utils.ts
62
62
 
@@ -116,7 +116,6 @@ function getMirror() {
116
116
  }
117
117
  function getBuilderConfig(options, resolvedConfig) {
118
118
  var _a;
119
- createPkg(options, resolvedConfig);
120
119
  const config = {
121
120
  directories: {
122
121
  buildResources: "electron/build",
@@ -227,13 +226,14 @@ function createPkg(options, resolvedConfig) {
227
226
  return newPkg;
228
227
  }
229
228
  async function runElectronBuilder(options, resolvedConfig) {
230
- if (typeof options.builder == "boolean" && options.builder == false) {
229
+ if (typeof options.builder == "boolean" && options.builder === false) {
231
230
  return;
232
231
  }
233
232
  logger.info("building electron app...");
234
233
  const DIST_PATH = _path2.default.join(_process.cwd.call(void 0, ), _path2.default.dirname(resolvedConfig.build.outDir));
234
+ createPkg(options, resolvedConfig);
235
235
  logger.info(`create package.json and exec "npm install"`);
236
- _shelljs2.default.exec(`cd ${DIST_PATH} && npm i`);
236
+ _shelljs2.default.exec(`cd ${DIST_PATH} && npm install --emit=dev`);
237
237
  logger.info(`run electron-builder to package app`);
238
238
  const config = getBuilderConfig(options, resolvedConfig);
239
239
  const { build } = await Promise.resolve().then(() => _interopRequireWildcard(require("electron-builder")));
@@ -312,7 +312,7 @@ async function runServe(options, server) {
312
312
  if (buildCounts[i] <= 0) {
313
313
  buildCounts[i]++;
314
314
  logger2.info(`${name} build success`);
315
- if (buildCounts[0] == 1 && buildCounts[1] == 1) {
315
+ if (buildCounts[0] === 1 && buildCounts[1] === 1) {
316
316
  logger2.info("startup electron");
317
317
  await startup(options);
318
318
  }
@@ -356,7 +356,7 @@ function preMergeOptions(options) {
356
356
  const pkg = getPkg();
357
357
  const format = pkg.type === "module" ? "esm" : "cjs";
358
358
  const electron2 = {
359
- target: ["es2021", "node16"],
359
+ target: format === "esm" ? "node18.18" : "node16",
360
360
  format,
361
361
  shims: true,
362
362
  clean: true,
@@ -388,7 +388,7 @@ function preMergeOptions(options) {
388
388
  const fmt = opt.format;
389
389
  opt.format = ["cjs", "esm"].includes(fmt) ? [fmt] : [format];
390
390
  const entry = opt.entry;
391
- if (entry == void 0) {
391
+ if (entry === void 0) {
392
392
  const filePath = `electron/${prop}/index.ts`;
393
393
  if (_fs2.default.existsSync(_path2.default.join(process.cwd(), filePath))) {
394
394
  opt.entry = [filePath];
@@ -426,7 +426,6 @@ function getBooleanValue(value) {
426
426
  if (["1", "0"].includes(value)) {
427
427
  return value === "1";
428
428
  }
429
- return;
430
429
  }
431
430
  function useElectronPlugin(options) {
432
431
  const opts = preMergeOptions(options);
@@ -486,8 +485,8 @@ function useElectronPlugin(options) {
486
485
  }
487
486
  };
488
487
  }
489
- var src_default = useElectronPlugin;
488
+ var index_default = useElectronPlugin;
490
489
 
491
490
 
492
491
 
493
- exports.default = src_default; exports.useElectronPlugin = useElectronPlugin;
492
+ exports.default = index_default; exports.useElectronPlugin = useElectronPlugin;
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  // src/index.ts
2
- import fs2 from "fs";
2
+ import fs2 from "node:fs";
3
+ import path2 from "node:path";
3
4
  import cloneDeep from "lodash.clonedeep";
4
5
  import merge2 from "lodash.merge";
5
- import path2 from "path";
6
6
 
7
7
  // src/builder.ts
8
- import os from "os";
9
- import path from "path";
10
- import { cwd } from "process";
8
+ import os from "node:os";
9
+ import path from "node:path";
10
+ import { cwd } from "node:process";
11
11
  import merge from "lodash.merge";
12
12
  import shell from "shelljs";
13
13
 
@@ -54,12 +54,12 @@ var Logger = class {
54
54
  console.log(`${this.getTime()}${green(this.tag)}`, msg, ...rest);
55
55
  }
56
56
  };
57
- var createLogger = (tag) => {
57
+ function createLogger(tag) {
58
58
  return new Logger(tag || PLUGIN_NAME, true);
59
- };
59
+ }
60
60
 
61
61
  // src/utils.ts
62
- import fs from "fs";
62
+ import fs from "node:fs";
63
63
  function readJson(path3) {
64
64
  if (fs.existsSync(path3)) {
65
65
  return JSON.parse(fs.readFileSync(path3, "utf8"));
@@ -115,7 +115,6 @@ function getMirror() {
115
115
  }
116
116
  function getBuilderConfig(options, resolvedConfig) {
117
117
  var _a;
118
- createPkg(options, resolvedConfig);
119
118
  const config = {
120
119
  directories: {
121
120
  buildResources: "electron/build",
@@ -226,13 +225,14 @@ function createPkg(options, resolvedConfig) {
226
225
  return newPkg;
227
226
  }
228
227
  async function runElectronBuilder(options, resolvedConfig) {
229
- if (typeof options.builder == "boolean" && options.builder == false) {
228
+ if (typeof options.builder == "boolean" && options.builder === false) {
230
229
  return;
231
230
  }
232
231
  logger.info("building electron app...");
233
232
  const DIST_PATH = path.join(cwd(), path.dirname(resolvedConfig.build.outDir));
233
+ createPkg(options, resolvedConfig);
234
234
  logger.info(`create package.json and exec "npm install"`);
235
- shell.exec(`cd ${DIST_PATH} && npm i`);
235
+ shell.exec(`cd ${DIST_PATH} && npm install --emit=dev`);
236
236
  logger.info(`run electron-builder to package app`);
237
237
  const config = getBuilderConfig(options, resolvedConfig);
238
238
  const { build } = await import("electron-builder");
@@ -242,7 +242,7 @@ async function runElectronBuilder(options, resolvedConfig) {
242
242
  }
243
243
 
244
244
  // src/main.ts
245
- import { spawn } from "child_process";
245
+ import { spawn } from "node:child_process";
246
246
  import electron from "electron";
247
247
  import treeKill from "tree-kill";
248
248
  import { build as tsupBuild } from "tsup";
@@ -311,7 +311,7 @@ async function runServe(options, server) {
311
311
  if (buildCounts[i] <= 0) {
312
312
  buildCounts[i]++;
313
313
  logger2.info(`${name} build success`);
314
- if (buildCounts[0] == 1 && buildCounts[1] == 1) {
314
+ if (buildCounts[0] === 1 && buildCounts[1] === 1) {
315
315
  logger2.info("startup electron");
316
316
  await startup(options);
317
317
  }
@@ -355,7 +355,7 @@ function preMergeOptions(options) {
355
355
  const pkg = getPkg();
356
356
  const format = pkg.type === "module" ? "esm" : "cjs";
357
357
  const electron2 = {
358
- target: ["es2021", "node16"],
358
+ target: format === "esm" ? "node18.18" : "node16",
359
359
  format,
360
360
  shims: true,
361
361
  clean: true,
@@ -387,7 +387,7 @@ function preMergeOptions(options) {
387
387
  const fmt = opt.format;
388
388
  opt.format = ["cjs", "esm"].includes(fmt) ? [fmt] : [format];
389
389
  const entry = opt.entry;
390
- if (entry == void 0) {
390
+ if (entry === void 0) {
391
391
  const filePath = `electron/${prop}/index.ts`;
392
392
  if (fs2.existsSync(path2.join(process.cwd(), filePath))) {
393
393
  opt.entry = [filePath];
@@ -425,7 +425,6 @@ function getBooleanValue(value) {
425
425
  if (["1", "0"].includes(value)) {
426
426
  return value === "1";
427
427
  }
428
- return;
429
428
  }
430
429
  function useElectronPlugin(options) {
431
430
  const opts = preMergeOptions(options);
@@ -485,8 +484,8 @@ function useElectronPlugin(options) {
485
484
  }
486
485
  };
487
486
  }
488
- var src_default = useElectronPlugin;
487
+ var index_default = useElectronPlugin;
489
488
  export {
490
- src_default as default,
489
+ index_default as default,
491
490
  useElectronPlugin
492
491
  };
package/package.json CHANGED
@@ -1,7 +1,17 @@
1
1
  {
2
2
  "name": "@tomjs/vite-plugin-electron",
3
- "version": "1.9.2",
3
+ "version": "1.11.0",
4
+ "packageManager": "pnpm@8.15.8",
4
5
  "description": "A simple vite plugin for electron, supports esm/cjs, support esm in electron v28+",
6
+ "author": {
7
+ "name": "Tom Gao",
8
+ "email": "tom@tomgao.cc"
9
+ },
10
+ "license": "MIT",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/tomjs/vite-plugin-electron.git"
14
+ },
5
15
  "keywords": [
6
16
  "vite",
7
17
  "plugin",
@@ -10,26 +20,21 @@
10
20
  "esm",
11
21
  "cjs"
12
22
  ],
13
- "author": {
14
- "name": "Tom Gao",
15
- "email": "tom@tomgao.cc"
16
- },
17
- "license": "MIT",
18
- "main": "./dist/index.js",
19
- "module": "./dist/index.mjs",
20
- "types": "./dist/index.d.ts",
21
23
  "exports": {
22
24
  ".": {
23
- "require": {
24
- "default": "./dist/index.js",
25
- "types": "./dist/index.d.ts"
26
- },
27
25
  "import": {
28
- "default": "./dist/index.mjs",
29
- "types": "./dist/index.d.mts"
26
+ "types": "./dist/index.d.mts",
27
+ "default": "./dist/index.mjs"
28
+ },
29
+ "require": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
30
32
  }
31
33
  }
32
34
  },
35
+ "main": "./dist/index.js",
36
+ "module": "./dist/index.mjs",
37
+ "types": "./dist/index.d.ts",
33
38
  "files": [
34
39
  "dist",
35
40
  "env.d.ts"
@@ -41,57 +46,50 @@
41
46
  "access": "public",
42
47
  "registry": "https://registry.npmjs.org/"
43
48
  },
44
- "repository": {
45
- "type": "git",
46
- "url": "git+https://github.com/tomjs/vite-plugin-electron.git"
49
+ "peerDependencies": {
50
+ "electron": ">=12.0.0",
51
+ "electron-builder": ">=24.2.0",
52
+ "vite": ">=2.9.0"
53
+ },
54
+ "peerDependenciesMeta": {
55
+ "electron-builder": {
56
+ "optional": true
57
+ }
47
58
  },
48
59
  "dependencies": {
49
- "dayjs": "^1.11.12",
60
+ "dayjs": "^1.11.13",
50
61
  "kolorist": "^1.8.0",
51
62
  "lodash.clonedeep": "^4.5.0",
52
63
  "lodash.merge": "^4.6.2",
53
- "shelljs": "^0.8.5",
64
+ "shelljs": "^0.10.0",
54
65
  "tree-kill": "^1.2.2",
55
- "tsup": "7.2.0"
66
+ "tsup": "^8.4.0"
56
67
  },
57
68
  "devDependencies": {
58
- "@commitlint/cli": "^19.3.0",
59
- "@tomjs/commitlint": "^3.3.0",
60
- "@tomjs/eslint": "^3.3.0",
61
- "@tomjs/prettier": "^1.4.1",
62
- "@tomjs/stylelint": "^2.6.1",
63
- "@tomjs/tsconfig": "^1.7.1",
69
+ "@commitlint/cli": "^19.8.1",
70
+ "@tomjs/commitlint": "^4.0.0",
71
+ "@tomjs/eslint": "^5.0.0",
72
+ "@tomjs/stylelint": "^6.0.0",
73
+ "@tomjs/tsconfig": "^1.7.2",
64
74
  "@types/lodash.clonedeep": "^4.5.9",
65
75
  "@types/lodash.merge": "^4.6.9",
66
- "@types/node": "^18.19.42",
67
- "@types/shelljs": "^0.8.15",
68
- "eslint": "^8.57.0",
69
- "husky": "^9.1.4",
70
- "lint-staged": "^15.2.7",
76
+ "@types/node": "^18.19.100",
77
+ "@types/shelljs": "^0.8.16",
78
+ "eslint": "^9.26.0",
79
+ "lint-staged": "^15.5.2",
71
80
  "npm-run-all": "^4.1.5",
72
- "prettier": "^3.3.3",
73
81
  "rimraf": "^6.0.1",
74
- "stylelint": "^16.8.1",
75
- "tsx": "^4.16.5",
76
- "typescript": "~5.5.4"
77
- },
78
- "peerDependencies": {
79
- "electron": ">=12.0.0",
80
- "electron-builder": ">=24.2.0",
81
- "vite": ">=2.9.0"
82
+ "simple-git-hooks": "^2.13.0",
83
+ "stylelint": "^16.19.1",
84
+ "tsx": "^4.19.4",
85
+ "typescript": "~5.8.3",
86
+ "vite": "^6.3.5"
82
87
  },
83
- "peerDependenciesMeta": {
84
- "electron-builder": {
85
- "optional": true
86
- }
87
- },
88
- "packageManager": "pnpm@8.15.8",
89
88
  "scripts": {
90
89
  "dev": "tsup --watch",
91
90
  "build": "tsup",
92
- "lint": "run-s lint:eslint lint:stylelint lint:prettier",
93
- "lint:eslint": "eslint \"{src,examples}/**/*.{js,cjs,ts,tsx,vue}\" *.{js,cjs,ts} --fix --cache",
91
+ "lint": "run-s lint:stylelint lint:eslint",
94
92
  "lint:stylelint": "stylelint \"examples/**/*.{css,scss,less,vue,html}\" --fix --cache",
95
- "lint:prettier": "prettier --write ."
93
+ "lint:eslint": "eslint --fix"
96
94
  }
97
95
  }