@tomjs/vite-plugin-electron 1.2.0 → 1.2.2
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 +38 -38
- package/README.zh_CN.md +37 -39
- package/dist/index.d.mts +6 -16
- package/dist/index.d.ts +6 -16
- package/dist/index.js +14 -10
- package/dist/index.mjs +14 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
> A Simple [vite](https://vitejs.dev/) plugin for [electron](https://www.electronjs.org), supports `esm` and `cjs`.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Many thanks to [caoxiemeihao](https://github.com/caoxiemeihao)'s [vite-plugin-electron](https://github.com/electron-vite/vite-plugin-electron) and [Doubleshotjs](https://github.com/Doubleshotjs)'s [doubleshot](https://github.com/Doubleshotjs/doubleshot) These two excellent libraries inspired me. I hope to use it to simplify development configuration and focus only on business development.
|
|
10
10
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
@@ -15,33 +15,28 @@ I learned [caoxiemeihao](https://github.com/caoxiemeihao)'s [vite-plugin-electro
|
|
|
15
15
|
- Support `main`'s `Hot Restart`
|
|
16
16
|
- Support `preload`'s `Hot Reload`
|
|
17
17
|
- Support `esm` and `cjs`, you can use `esm` in [electron v28+](https://www.electronjs.org/blog/electron-28-0)
|
|
18
|
-
- Support `vue` and `react` and
|
|
18
|
+
- Support `vue` and `react` and other [frameworks](https://vitejs.dev/guide/#trying-vite-online) supported by `vite`
|
|
19
19
|
|
|
20
20
|
## Install
|
|
21
21
|
|
|
22
|
-
With `pnpm`
|
|
23
|
-
|
|
24
22
|
```bash
|
|
23
|
+
# pnpm
|
|
25
24
|
pnpm add @tomjs/vite-plugin-electron -D
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
With `yarn`
|
|
29
25
|
|
|
30
|
-
|
|
26
|
+
# yarn
|
|
31
27
|
yarn add @tomjs/vite-plugin-electron -D
|
|
32
|
-
```
|
|
33
28
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
```bash
|
|
29
|
+
# npm
|
|
37
30
|
npm i @tomjs/vite-plugin-electron --save-dev
|
|
38
31
|
```
|
|
39
32
|
|
|
40
33
|
## Usage
|
|
41
34
|
|
|
42
|
-
###
|
|
35
|
+
### Recommended Agreement
|
|
43
36
|
|
|
44
|
-
|
|
37
|
+
#### Directory Structure
|
|
38
|
+
|
|
39
|
+
- Recommend `electron` and page `src` code directory structure
|
|
45
40
|
|
|
46
41
|
```
|
|
47
42
|
|--electron
|
|
@@ -54,7 +49,7 @@ npm i @tomjs/vite-plugin-electron --save-dev
|
|
|
54
49
|
| |--main.ts
|
|
55
50
|
```
|
|
56
51
|
|
|
57
|
-
-
|
|
52
|
+
- Zero configuration, default dist output directory
|
|
58
53
|
|
|
59
54
|
```
|
|
60
55
|
|--dist
|
|
@@ -68,6 +63,10 @@ npm i @tomjs/vite-plugin-electron --save-dev
|
|
|
68
63
|
| | |--index.html
|
|
69
64
|
```
|
|
70
65
|
|
|
66
|
+
#### Default configuration and behavior
|
|
67
|
+
|
|
68
|
+
See [PluginOptions](#pluginoptions) and `recommended` parameter descriptions in detail
|
|
69
|
+
|
|
71
70
|
### electron
|
|
72
71
|
|
|
73
72
|
`electron/main/index.ts`
|
|
@@ -107,10 +106,12 @@ app.whenReady().then(createWindow);
|
|
|
107
106
|
|
|
108
107
|
### vue
|
|
109
108
|
|
|
110
|
-
|
|
109
|
+
Take using `esm` as an example, but it requires Electron>=28
|
|
111
110
|
|
|
112
111
|
- `package.json`
|
|
113
112
|
|
|
113
|
+
Electron preload must use the `mjs` suffix, otherwise an error will be reported. So `esm` also uses the `mjs` suffix for output by default.
|
|
114
|
+
|
|
114
115
|
```json
|
|
115
116
|
{
|
|
116
117
|
"type": "module",
|
|
@@ -128,14 +129,17 @@ import vue from '@vitejs/plugin-vue';
|
|
|
128
129
|
export default defineConfig({
|
|
129
130
|
plugins: [
|
|
130
131
|
vue(),
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
132
|
+
// If you use the agreed directory structure, no configuration is required
|
|
133
|
+
electron(),
|
|
134
|
+
// If the directory structure is customized, the value must be assigned according to the actual situation
|
|
135
|
+
// electron({
|
|
136
|
+
// main: {
|
|
137
|
+
// entry: 'electron/main/index.ts',
|
|
138
|
+
// },
|
|
139
|
+
// preload: {
|
|
140
|
+
// entry: 'electron/preload/index.ts',
|
|
141
|
+
// },
|
|
142
|
+
// }),
|
|
139
143
|
// renderer(),
|
|
140
144
|
],
|
|
141
145
|
});
|
|
@@ -143,7 +147,7 @@ export default defineConfig({
|
|
|
143
147
|
|
|
144
148
|
### react
|
|
145
149
|
|
|
146
|
-
|
|
150
|
+
Take using `cjs` as an example
|
|
147
151
|
|
|
148
152
|
- `package.json`
|
|
149
153
|
|
|
@@ -158,23 +162,11 @@ Support `CommonJS`
|
|
|
158
162
|
|
|
159
163
|
```ts
|
|
160
164
|
import { defineConfig } from 'vite';
|
|
161
|
-
// import renderer from 'vite-plugin-electron-renderer'; // Enable nodeIntegration
|
|
162
165
|
import electron from '@tomjs/vite-plugin-electron';
|
|
163
166
|
import react from '@vitejs/plugin-react-swc';
|
|
164
167
|
|
|
165
168
|
export default defineConfig({
|
|
166
|
-
plugins: [
|
|
167
|
-
react(),
|
|
168
|
-
electron({
|
|
169
|
-
main: {
|
|
170
|
-
entry: 'electron/main/index.ts',
|
|
171
|
-
},
|
|
172
|
-
preload: {
|
|
173
|
-
entry: 'electron/preload/index.ts',
|
|
174
|
-
},
|
|
175
|
-
}),
|
|
176
|
-
// renderer(),
|
|
177
|
-
],
|
|
169
|
+
plugins: [react(), electron()],
|
|
178
170
|
});
|
|
179
171
|
```
|
|
180
172
|
|
|
@@ -195,6 +187,14 @@ export default defineConfig({
|
|
|
195
187
|
| preload | [PreloadOptions](#PreloadOptions) | | Configuration options for the electron preload process. |
|
|
196
188
|
| inspect | `boolean` | true | If set to true, electron will start with the `--inspect` flag. |
|
|
197
189
|
|
|
190
|
+
**Notice**
|
|
191
|
+
|
|
192
|
+
The `recommended` option is used to set the default configuration and behavior, which can be used with almost zero configuration. The default is `true`. If you want to customize the configuration, set it to `false`. The following default prerequisites are to use the recommended [project structure](#directory-structure).
|
|
193
|
+
|
|
194
|
+
- Check whether `electron/main/index.ts` and `electron/main/index.ts` exist, and if so, assign values to `main.entry` and `preload.entry` respectively. If it does not exist, `main.entry` must be actively assigned, and an error will be reported.
|
|
195
|
+
- The output directory is based on the `build.outDir` parameter of `vite`, and outputs `electron/main`, `electron/preload` and `src` to `dist/main`, `dist/preload` and `dist/renderer` respectively.
|
|
196
|
+
- Other behaviors to be implemented
|
|
197
|
+
|
|
198
198
|
### MainOptions
|
|
199
199
|
|
|
200
200
|
Based on [Options](https://paka.dev/npm/tsup) of [tsup](https://tsup.egoist.dev/), some default values are added for ease of use.
|
package/README.zh_CN.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
> 一个简单的 [electron](https://www.electronjs.org/zh/) [vite](https://cn.vitejs.dev/) 插件,支持 `esm` 和 `cjs`
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
非常感谢 [caoxiemeihao](https://github.com/caoxiemeihao) 的 [vite-plugin-electron](https://github.com/electron-vite/vite-plugin-electron) 和 [Doubleshotjs](https://github.com/Doubleshotjs) 的 [doubleshot](https://github.com/Doubleshotjs/doubleshot) 这两个优秀库给了我启发。我希望使用它能简化开发配置,只关注业务开发。
|
|
10
10
|
|
|
11
11
|
## 特性
|
|
12
12
|
|
|
@@ -15,33 +15,28 @@
|
|
|
15
15
|
- 支持 `main` 的 `热重启`
|
|
16
16
|
- 支持 `preload` 的 `热重载`
|
|
17
17
|
- 支持 `esm` 和 `cjs` ,你可以在 [electron v28+](https://www.electronjs.org/zh/blog/electron-28-0) 中使用 `esm`
|
|
18
|
-
- 支持 `vue` 和 `react`
|
|
18
|
+
- 支持 `vue` 和 `react` 等其他 `vite` 支持的[框架](https://cn.vitejs.dev/guide/#trying-vite-online)
|
|
19
19
|
|
|
20
20
|
## 安装
|
|
21
21
|
|
|
22
|
-
使用 `pnpm`
|
|
23
|
-
|
|
24
22
|
```bash
|
|
23
|
+
# pnpm
|
|
25
24
|
pnpm add @tomjs/vite-plugin-electron -D
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
使用 `yarn`
|
|
29
25
|
|
|
30
|
-
|
|
26
|
+
# yarn
|
|
31
27
|
yarn add @tomjs/vite-plugin-electron -D
|
|
32
|
-
```
|
|
33
28
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
```bash
|
|
29
|
+
# npm
|
|
37
30
|
npm i @tomjs/vite-plugin-electron --save-dev
|
|
38
31
|
```
|
|
39
32
|
|
|
40
33
|
## 使用说明
|
|
41
34
|
|
|
42
|
-
###
|
|
35
|
+
### 推荐约定
|
|
43
36
|
|
|
44
|
-
|
|
37
|
+
#### 目录结构
|
|
38
|
+
|
|
39
|
+
- 推荐 `electron` 和 页面 `src` 代码目录结构
|
|
45
40
|
|
|
46
41
|
```
|
|
47
42
|
|--electron
|
|
@@ -54,7 +49,7 @@ npm i @tomjs/vite-plugin-electron --save-dev
|
|
|
54
49
|
| |--main.ts
|
|
55
50
|
```
|
|
56
51
|
|
|
57
|
-
-
|
|
52
|
+
- 零配置,默认 dist 输出目录
|
|
58
53
|
|
|
59
54
|
```
|
|
60
55
|
|--dist
|
|
@@ -68,6 +63,10 @@ npm i @tomjs/vite-plugin-electron --save-dev
|
|
|
68
63
|
| | |--index.html
|
|
69
64
|
```
|
|
70
65
|
|
|
66
|
+
#### 默认配置和行为
|
|
67
|
+
|
|
68
|
+
详细查看 [PluginOptions](#pluginoptions) 和 `recommended` 参数说明
|
|
69
|
+
|
|
71
70
|
### electron
|
|
72
71
|
|
|
73
72
|
`electron/main/index.ts`
|
|
@@ -107,10 +106,12 @@ app.whenReady().then(createWindow);
|
|
|
107
106
|
|
|
108
107
|
### vue
|
|
109
108
|
|
|
110
|
-
|
|
109
|
+
以使用 `esm` 为例,不过要求 `Electron>=28`
|
|
111
110
|
|
|
112
111
|
- `package.json`
|
|
113
112
|
|
|
113
|
+
Electron preload 必须使用 `mjs` 后缀,否则报错。所以 `esm` 也默认输出使用 `mjs` 后缀。
|
|
114
|
+
|
|
114
115
|
```json
|
|
115
116
|
{
|
|
116
117
|
"type": "module",
|
|
@@ -129,14 +130,17 @@ import vue from '@vitejs/plugin-vue';
|
|
|
129
130
|
export default defineConfig({
|
|
130
131
|
plugins: [
|
|
131
132
|
vue(),
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
133
|
+
// 如使用约定的目录结构,则不需要配置
|
|
134
|
+
electron(),
|
|
135
|
+
// 如果自定义了目录结构,则必须根据实际情况赋值
|
|
136
|
+
// electron({
|
|
137
|
+
// main: {
|
|
138
|
+
// entry: 'electron/main/index.ts',
|
|
139
|
+
// },
|
|
140
|
+
// preload: {
|
|
141
|
+
// entry: 'electron/preload/index.ts',
|
|
142
|
+
// },
|
|
143
|
+
// }),
|
|
140
144
|
// renderer(),
|
|
141
145
|
],
|
|
142
146
|
});
|
|
@@ -144,7 +148,7 @@ export default defineConfig({
|
|
|
144
148
|
|
|
145
149
|
### react
|
|
146
150
|
|
|
147
|
-
|
|
151
|
+
以使用 `cjs` 为例
|
|
148
152
|
|
|
149
153
|
- `package.json`
|
|
150
154
|
|
|
@@ -159,23 +163,11 @@ export default defineConfig({
|
|
|
159
163
|
|
|
160
164
|
```ts
|
|
161
165
|
import { defineConfig } from 'vite';
|
|
162
|
-
// import renderer from 'vite-plugin-electron-renderer'; // 启用 nodeIntegration
|
|
163
166
|
import electron from '@tomjs/vite-plugin-electron';
|
|
164
167
|
import react from '@vitejs/plugin-react-swc';
|
|
165
168
|
|
|
166
169
|
export default defineConfig({
|
|
167
|
-
plugins: [
|
|
168
|
-
react(),
|
|
169
|
-
electron({
|
|
170
|
-
main: {
|
|
171
|
-
entry: 'electron/main/index.ts',
|
|
172
|
-
},
|
|
173
|
-
preload: {
|
|
174
|
-
entry: 'electron/preload/index.ts',
|
|
175
|
-
},
|
|
176
|
-
}),
|
|
177
|
-
// renderer(),
|
|
178
|
-
],
|
|
170
|
+
plugins: [react(), electron()],
|
|
179
171
|
});
|
|
180
172
|
```
|
|
181
173
|
|
|
@@ -192,10 +184,16 @@ export default defineConfig({
|
|
|
192
184
|
| --- | --- | --- | --- |
|
|
193
185
|
| recommended | `boolean` | `true` | 推荐开关,如果为true,将具有以下默认行为:将main/preload/renderer的outDir更改为并行的outDir;例如,如果vite build.outDir为'dist',将main/preload/render更改为'dist/main'、'dist/preload'和'dist/renderer' |
|
|
194
186
|
| external | `string[]` | | 不打包这些模块 |
|
|
195
|
-
|
|
|
187
|
+
| main | [MainOptions](#MainOptions) | | electron main 进程选项 |
|
|
196
188
|
| preload | [PreloadOptions](#PreloadOptions) | | electron preload 进程选项 |
|
|
197
189
|
| inspect | `boolean` | `true` | electron启动时使用`--inspect`参数 |
|
|
198
190
|
|
|
191
|
+
`recommended` 选项用于设置默认配置和行为,几乎可以达到零配置使用,默认为 `true` 。如果你要自定义配置,请设置它为`false`。以下默认的前提条件是使用推荐的 [项目结构](#目录结构)。
|
|
192
|
+
|
|
193
|
+
- 检查是否存在 `electron/main/index.ts` 和 `electron/main/index.ts`,如果有则分别给 `main.entry` 和 `preload.entry` 赋值。如果不存在,`main.entry` 必须主动赋值,负责会报错
|
|
194
|
+
- 输出目录根据 `vite` 的 `build.outDir` 参数, 将 `electron/main`、`electron/preload`、`src` 分别输出到 `dist/main`、`dist/preload`、`dist/renderer`
|
|
195
|
+
- 其他待实现的行为
|
|
196
|
+
|
|
199
197
|
### MainOptions
|
|
200
198
|
|
|
201
199
|
继承自 [tsup](https://tsup.egoist.dev/) 的 [Options](https://paka.dev/npm/tsup),添加了一些默认值,方便使用。
|
package/dist/index.d.mts
CHANGED
|
@@ -2,20 +2,15 @@ import { Plugin } from 'vite';
|
|
|
2
2
|
import { Options } from 'tsup';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Electron main process options.
|
|
5
|
+
* Electron main process options. See [tsup](https://tsup.egoist.dev/) and [API Doc](https://paka.dev/npm/tsup) for more information.
|
|
6
6
|
* @see https://paka.dev/npm/tsup
|
|
7
7
|
* @see https://unpkg.com/browse/tsup/dist/index.d.ts
|
|
8
8
|
*/
|
|
9
|
-
interface MainOptions extends Omit<Options, '
|
|
10
|
-
/**
|
|
11
|
-
* The name of the electron main process.
|
|
12
|
-
* @default "main"
|
|
13
|
-
*/
|
|
14
|
-
name?: string;
|
|
9
|
+
interface MainOptions extends Omit<Options, 'entry' | 'format' | 'outDir' | 'watch' | 'onSuccess'> {
|
|
15
10
|
/**
|
|
16
11
|
* The main process entry file.
|
|
17
12
|
*/
|
|
18
|
-
entry
|
|
13
|
+
entry?: string;
|
|
19
14
|
/**
|
|
20
15
|
* The bundle format. If not specified, it will use the "type" field from package.json.
|
|
21
16
|
*/
|
|
@@ -31,16 +26,11 @@ interface MainOptions extends Omit<Options, 'name' | 'entry' | 'format' | 'outDi
|
|
|
31
26
|
onSuccess?: () => Promise<void | undefined | (() => void | Promise<void>)>;
|
|
32
27
|
}
|
|
33
28
|
/**
|
|
34
|
-
* Electron preload process options.
|
|
29
|
+
* Electron preload process options. See [tsup](https://tsup.egoist.dev/) and [API Doc](https://paka.dev/npm/tsup) for more information.
|
|
35
30
|
* @see https://paka.dev/npm/tsup
|
|
36
31
|
* @see https://unpkg.com/browse/tsup/dist/index.d.ts
|
|
37
32
|
*/
|
|
38
|
-
interface PreloadOptions extends Omit<Options, '
|
|
39
|
-
/**
|
|
40
|
-
* The name of the electron preload process.
|
|
41
|
-
* @default "preload"
|
|
42
|
-
*/
|
|
43
|
-
name?: string;
|
|
33
|
+
interface PreloadOptions extends Omit<Options, 'entry' | 'format' | 'outDir' | 'watch' | 'onSuccess'> {
|
|
44
34
|
/**
|
|
45
35
|
* The preload process entry file
|
|
46
36
|
*/
|
|
@@ -78,7 +68,7 @@ interface PluginOptions {
|
|
|
78
68
|
/**
|
|
79
69
|
* electron main process options
|
|
80
70
|
*/
|
|
81
|
-
main
|
|
71
|
+
main?: MainOptions;
|
|
82
72
|
/**
|
|
83
73
|
* electron preload process options
|
|
84
74
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -2,20 +2,15 @@ import { Plugin } from 'vite';
|
|
|
2
2
|
import { Options } from 'tsup';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Electron main process options.
|
|
5
|
+
* Electron main process options. See [tsup](https://tsup.egoist.dev/) and [API Doc](https://paka.dev/npm/tsup) for more information.
|
|
6
6
|
* @see https://paka.dev/npm/tsup
|
|
7
7
|
* @see https://unpkg.com/browse/tsup/dist/index.d.ts
|
|
8
8
|
*/
|
|
9
|
-
interface MainOptions extends Omit<Options, '
|
|
10
|
-
/**
|
|
11
|
-
* The name of the electron main process.
|
|
12
|
-
* @default "main"
|
|
13
|
-
*/
|
|
14
|
-
name?: string;
|
|
9
|
+
interface MainOptions extends Omit<Options, 'entry' | 'format' | 'outDir' | 'watch' | 'onSuccess'> {
|
|
15
10
|
/**
|
|
16
11
|
* The main process entry file.
|
|
17
12
|
*/
|
|
18
|
-
entry
|
|
13
|
+
entry?: string;
|
|
19
14
|
/**
|
|
20
15
|
* The bundle format. If not specified, it will use the "type" field from package.json.
|
|
21
16
|
*/
|
|
@@ -31,16 +26,11 @@ interface MainOptions extends Omit<Options, 'name' | 'entry' | 'format' | 'outDi
|
|
|
31
26
|
onSuccess?: () => Promise<void | undefined | (() => void | Promise<void>)>;
|
|
32
27
|
}
|
|
33
28
|
/**
|
|
34
|
-
* Electron preload process options.
|
|
29
|
+
* Electron preload process options. See [tsup](https://tsup.egoist.dev/) and [API Doc](https://paka.dev/npm/tsup) for more information.
|
|
35
30
|
* @see https://paka.dev/npm/tsup
|
|
36
31
|
* @see https://unpkg.com/browse/tsup/dist/index.d.ts
|
|
37
32
|
*/
|
|
38
|
-
interface PreloadOptions extends Omit<Options, '
|
|
39
|
-
/**
|
|
40
|
-
* The name of the electron preload process.
|
|
41
|
-
* @default "preload"
|
|
42
|
-
*/
|
|
43
|
-
name?: string;
|
|
33
|
+
interface PreloadOptions extends Omit<Options, 'entry' | 'format' | 'outDir' | 'watch' | 'onSuccess'> {
|
|
44
34
|
/**
|
|
45
35
|
* The preload process entry file
|
|
46
36
|
*/
|
|
@@ -78,7 +68,7 @@ interface PluginOptions {
|
|
|
78
68
|
/**
|
|
79
69
|
* electron main process options
|
|
80
70
|
*/
|
|
81
|
-
main
|
|
71
|
+
main?: MainOptions;
|
|
82
72
|
/**
|
|
83
73
|
* electron preload process options
|
|
84
74
|
*/
|
package/dist/index.js
CHANGED
|
@@ -172,11 +172,9 @@ function preMergeOptions(options) {
|
|
|
172
172
|
recommended: true,
|
|
173
173
|
external: ["electron"],
|
|
174
174
|
main: {
|
|
175
|
-
name: "main",
|
|
176
175
|
...electron2
|
|
177
176
|
},
|
|
178
177
|
preload: {
|
|
179
|
-
name: "payload",
|
|
180
178
|
...electron2
|
|
181
179
|
}
|
|
182
180
|
},
|
|
@@ -187,7 +185,12 @@ function preMergeOptions(options) {
|
|
|
187
185
|
const fmt = opt.format;
|
|
188
186
|
opt.format = ["cjs", "esm"].includes(fmt) ? [fmt] : [format];
|
|
189
187
|
const entry = opt.entry;
|
|
190
|
-
if (
|
|
188
|
+
if (entry == void 0) {
|
|
189
|
+
const filePath = `electron/${prop}/index.ts`;
|
|
190
|
+
if (_fs2.default.existsSync(_path2.default.join(process.cwd(), filePath))) {
|
|
191
|
+
opt.entry = [filePath];
|
|
192
|
+
}
|
|
193
|
+
} else if (typeof entry === "string") {
|
|
191
194
|
opt.entry = [entry];
|
|
192
195
|
}
|
|
193
196
|
const external = opt.external || opts.external || ["electron"];
|
|
@@ -205,21 +208,22 @@ function vitePluginElectron(options) {
|
|
|
205
208
|
var _a;
|
|
206
209
|
isServer = env.command === "serve";
|
|
207
210
|
let outDir = ((_a = config == null ? void 0 : config.build) == null ? void 0 : _a.outDir) || "dist";
|
|
208
|
-
opts.
|
|
211
|
+
opts.main ||= {};
|
|
212
|
+
opts.preload ||= {};
|
|
209
213
|
if (opts.recommended) {
|
|
210
214
|
opts.main.outDir = _path2.default.join(outDir, "main");
|
|
211
215
|
opts.preload.outDir = _path2.default.join(outDir, "preload");
|
|
212
216
|
outDir = _path2.default.join(outDir, "renderer");
|
|
213
217
|
} else {
|
|
214
|
-
opts.main.outDir
|
|
215
|
-
opts.preload.outDir
|
|
218
|
+
opts.main.outDir ||= _path2.default.join("dist-electron", "main");
|
|
219
|
+
opts.preload.outDir ||= _path2.default.join("dist-electron", "preload");
|
|
216
220
|
}
|
|
217
221
|
if (isDev) {
|
|
218
|
-
opts.main.sourcemap
|
|
219
|
-
opts.preload.sourcemap
|
|
222
|
+
opts.main.sourcemap ??= true;
|
|
223
|
+
opts.preload.sourcemap ??= true;
|
|
220
224
|
} else {
|
|
221
|
-
opts.main.minify
|
|
222
|
-
opts.preload.minify
|
|
225
|
+
opts.main.minify ??= true;
|
|
226
|
+
opts.preload.minify ??= true;
|
|
223
227
|
}
|
|
224
228
|
return {
|
|
225
229
|
build: {
|
package/dist/index.mjs
CHANGED
|
@@ -171,11 +171,9 @@ function preMergeOptions(options) {
|
|
|
171
171
|
recommended: true,
|
|
172
172
|
external: ["electron"],
|
|
173
173
|
main: {
|
|
174
|
-
name: "main",
|
|
175
174
|
...electron2
|
|
176
175
|
},
|
|
177
176
|
preload: {
|
|
178
|
-
name: "payload",
|
|
179
177
|
...electron2
|
|
180
178
|
}
|
|
181
179
|
},
|
|
@@ -186,7 +184,12 @@ function preMergeOptions(options) {
|
|
|
186
184
|
const fmt = opt.format;
|
|
187
185
|
opt.format = ["cjs", "esm"].includes(fmt) ? [fmt] : [format];
|
|
188
186
|
const entry = opt.entry;
|
|
189
|
-
if (
|
|
187
|
+
if (entry == void 0) {
|
|
188
|
+
const filePath = `electron/${prop}/index.ts`;
|
|
189
|
+
if (fs2.existsSync(path.join(process.cwd(), filePath))) {
|
|
190
|
+
opt.entry = [filePath];
|
|
191
|
+
}
|
|
192
|
+
} else if (typeof entry === "string") {
|
|
190
193
|
opt.entry = [entry];
|
|
191
194
|
}
|
|
192
195
|
const external = opt.external || opts.external || ["electron"];
|
|
@@ -204,21 +207,22 @@ function vitePluginElectron(options) {
|
|
|
204
207
|
var _a;
|
|
205
208
|
isServer = env.command === "serve";
|
|
206
209
|
let outDir = ((_a = config == null ? void 0 : config.build) == null ? void 0 : _a.outDir) || "dist";
|
|
207
|
-
opts.
|
|
210
|
+
opts.main ||= {};
|
|
211
|
+
opts.preload ||= {};
|
|
208
212
|
if (opts.recommended) {
|
|
209
213
|
opts.main.outDir = path.join(outDir, "main");
|
|
210
214
|
opts.preload.outDir = path.join(outDir, "preload");
|
|
211
215
|
outDir = path.join(outDir, "renderer");
|
|
212
216
|
} else {
|
|
213
|
-
opts.main.outDir
|
|
214
|
-
opts.preload.outDir
|
|
217
|
+
opts.main.outDir ||= path.join("dist-electron", "main");
|
|
218
|
+
opts.preload.outDir ||= path.join("dist-electron", "preload");
|
|
215
219
|
}
|
|
216
220
|
if (isDev) {
|
|
217
|
-
opts.main.sourcemap
|
|
218
|
-
opts.preload.sourcemap
|
|
221
|
+
opts.main.sourcemap ??= true;
|
|
222
|
+
opts.preload.sourcemap ??= true;
|
|
219
223
|
} else {
|
|
220
|
-
opts.main.minify
|
|
221
|
-
opts.preload.minify
|
|
224
|
+
opts.main.minify ??= true;
|
|
225
|
+
opts.preload.minify ??= true;
|
|
222
226
|
}
|
|
223
227
|
return {
|
|
224
228
|
build: {
|