@tomjs/vite-plugin-electron 1.4.0 → 1.5.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 +5 -3
- package/README.zh_CN.md +5 -3
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +17 -11
- package/dist/index.mjs +17 -11
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -126,12 +126,14 @@ Take using `esm` as an example, but it requires Electron>=28
|
|
|
126
126
|
|
|
127
127
|
- `package.json`
|
|
128
128
|
|
|
129
|
-
Electron preload must use the
|
|
129
|
+
Electron `preload process` must use the `.mjs` suffix, otherwise an error will be reported, see [official documentation](https://www.electronjs.org/zh/docs/latest/tutorial/esm). So the default output of `esm` of `preload` uses the `.mjs` suffix.
|
|
130
|
+
|
|
131
|
+
When the suffix of Electron `main process` is `.mjs` or `.cjs`, vscode breakpoint debugging cannot work, so the suffix defaults to `.js`.
|
|
130
132
|
|
|
131
133
|
```json
|
|
132
134
|
{
|
|
133
135
|
"type": "module",
|
|
134
|
-
"main": "dist/main/index.
|
|
136
|
+
"main": "dist/main/index.js"
|
|
135
137
|
}
|
|
136
138
|
```
|
|
137
139
|
|
|
@@ -202,6 +204,7 @@ export default defineConfig({
|
|
|
202
204
|
| main | [MainOptions](#MainOptions) | | Configuration options for the electron main process. |
|
|
203
205
|
| preload | [PreloadOptions](#PreloadOptions) | | Configuration options for the electron preload process. |
|
|
204
206
|
| debug | `boolean` | `false` | Electron debug mode, don't startup electron. You can also use `process.env.APP_ELECTRON_DEBUG`. Default is false. |
|
|
207
|
+
| 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.APP_ELECTRON_DEBUG`. |
|
|
205
208
|
| 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. |
|
|
206
209
|
|
|
207
210
|
**Notice**
|
|
@@ -247,7 +250,6 @@ To use this function, you need to install additional `electron-builder`
|
|
|
247
250
|
|
|
248
251
|
| Property | Type | Default | Description |
|
|
249
252
|
| --- | --- | --- | --- |
|
|
250
|
-
| enable | `boolean` | `false` | Whether to enable the [electron-builder](https://www.electron.build). |
|
|
251
253
|
| appId | `string` | `"com.electron.${name}"` | The application id. [See More](https://www.electron.build/configuration/configuration#configuration) |
|
|
252
254
|
| productName | `string` | `"com.electron.${name}"` | product name.[See More](https://www.electron.build/configuration/configuration#configuration) |
|
|
253
255
|
| 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) |
|
package/README.zh_CN.md
CHANGED
|
@@ -126,12 +126,14 @@ app.whenReady().then(createWindow);
|
|
|
126
126
|
|
|
127
127
|
- `package.json`
|
|
128
128
|
|
|
129
|
-
Electron preload 必须使用
|
|
129
|
+
Electron `preload process` 必须使用 `.mjs` 后缀,否则报错,查看[官方文档](https://www.electronjs.org/zh/docs/latest/tutorial/esm)。所以 `preload` 的 `esm` 默认输出使用 `mjs` 后缀。
|
|
130
|
+
|
|
131
|
+
当 Electron `main process` 的后缀为 `.mjs`或`.cjs` 时, vscode 断点调试无法起到作用,所以后缀默认为`.js`。
|
|
130
132
|
|
|
131
133
|
```json
|
|
132
134
|
{
|
|
133
135
|
"type": "module",
|
|
134
|
-
"main": "dist/main/index.
|
|
136
|
+
"main": "dist/main/index.js"
|
|
135
137
|
}
|
|
136
138
|
```
|
|
137
139
|
|
|
@@ -203,6 +205,7 @@ export default defineConfig({
|
|
|
203
205
|
| main | [MainOptions](#MainOptions) | | electron main 进程选项 |
|
|
204
206
|
| preload | [PreloadOptions](#PreloadOptions) | | electron preload 进程选项 |
|
|
205
207
|
| debug | `boolean` | `false` | Electron调试模式,不启动Electron。 您还可以使用 `process.env.APP_ELECTRON_DEBUG` |
|
|
208
|
+
| 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.APP_ELECTRON_DEBUG` 开启它。 |
|
|
206
209
|
| 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)。 |
|
|
207
210
|
|
|
208
211
|
`recommended` 选项用于设置默认配置和行为,几乎可以达到零配置使用,默认为 `true` 。如果你要自定义配置,请设置它为`false`。以下默认的前提条件是使用推荐的 [项目结构](#目录结构)。
|
|
@@ -246,7 +249,6 @@ _不适合所有人使用。_
|
|
|
246
249
|
|
|
247
250
|
| 参数名 | 类型 | 默认值 | 说明 |
|
|
248
251
|
| --- | --- | --- | --- |
|
|
249
|
-
| enable | `boolean` | `false` | 是否启用 [electron-builder](https://www.electron.build) |
|
|
250
252
|
| appId | `string` | `"com.electron.${name}"` | 应用程序 ID。[详细](https://www.electron.build/configuration/configuration#configuration) |
|
|
251
253
|
| productName | `string` | `` | 应用程序名称。[详细](https://www.electron.build/configuration/configuration#configuration) |
|
|
252
254
|
| builderConfig | [Configuration](https://www.electron.build/configuration/configuration#configurationF) | `undefined` | [electron-builder](https://www.electron.build) 的 [Configuration](https://www.electron.build/configuration/configuration#configuration) |
|
package/dist/index.d.mts
CHANGED
|
@@ -59,7 +59,8 @@ interface PreloadOptions extends Omit<Options, 'entry' | 'format' | 'outDir' | '
|
|
|
59
59
|
interface BuilderOptions {
|
|
60
60
|
/**
|
|
61
61
|
* Whether to enable the [electron-builder](https://www.electron.build), the default is false.
|
|
62
|
-
* @default
|
|
62
|
+
* @default true
|
|
63
|
+
* @deprecated
|
|
63
64
|
*/
|
|
64
65
|
enable?: boolean;
|
|
65
66
|
/**
|
|
@@ -109,7 +110,7 @@ interface PluginOptions {
|
|
|
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.
|
|
110
111
|
* * Execute `npm install` and then package.
|
|
111
112
|
*/
|
|
112
|
-
builder?: BuilderOptions;
|
|
113
|
+
builder?: boolean | BuilderOptions;
|
|
113
114
|
/**
|
|
114
115
|
* electron debug mode, don't startup electron. You can also use `process.env.APP_ELECTRON_DEBUG`. Default is false.
|
|
115
116
|
* @default false
|
package/dist/index.d.ts
CHANGED
|
@@ -59,7 +59,8 @@ interface PreloadOptions extends Omit<Options, 'entry' | 'format' | 'outDir' | '
|
|
|
59
59
|
interface BuilderOptions {
|
|
60
60
|
/**
|
|
61
61
|
* Whether to enable the [electron-builder](https://www.electron.build), the default is false.
|
|
62
|
-
* @default
|
|
62
|
+
* @default true
|
|
63
|
+
* @deprecated
|
|
63
64
|
*/
|
|
64
65
|
enable?: boolean;
|
|
65
66
|
/**
|
|
@@ -109,7 +110,7 @@ interface PluginOptions {
|
|
|
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.
|
|
110
111
|
* * Execute `npm install` and then package.
|
|
111
112
|
*/
|
|
112
|
-
builder?: BuilderOptions;
|
|
113
|
+
builder?: boolean | BuilderOptions;
|
|
113
114
|
/**
|
|
114
115
|
* electron debug mode, don't startup electron. You can also use `process.env.APP_ELECTRON_DEBUG`. Default is false.
|
|
115
116
|
* @default false
|
package/dist/index.js
CHANGED
|
@@ -71,7 +71,7 @@ function readJson(path3) {
|
|
|
71
71
|
function writeJson(path3, data) {
|
|
72
72
|
_fs2.default.writeFileSync(path3, JSON.stringify(data, null, 2), "utf8");
|
|
73
73
|
}
|
|
74
|
-
function exec(command, args, options) {
|
|
74
|
+
function exec(command, args = [], options) {
|
|
75
75
|
return _child_process.spawnSync.call(void 0, command, args, Object.assign({ encoding: "utf8" }, options));
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -131,6 +131,9 @@ function getBuilderConfig(options, resolvedConfig) {
|
|
|
131
131
|
deleteAppDataOnUninstall: false
|
|
132
132
|
}
|
|
133
133
|
};
|
|
134
|
+
if (typeof options.builder == "boolean") {
|
|
135
|
+
return config;
|
|
136
|
+
}
|
|
134
137
|
const { appId, productName } = options.builder || {};
|
|
135
138
|
return _lodashmerge2.default.call(void 0, config, { appId, productName }, (_a = options.builder) == null ? void 0 : _a.builderConfig);
|
|
136
139
|
}
|
|
@@ -205,6 +208,9 @@ function createPkg(options, resolvedConfig) {
|
|
|
205
208
|
return newPkg;
|
|
206
209
|
}
|
|
207
210
|
async function runElectronBuilder(options, resolvedConfig) {
|
|
211
|
+
if (typeof options.builder == "boolean" && options.builder == false) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
208
214
|
logger.info("building electron app...");
|
|
209
215
|
const DIST_PATH = _path2.default.join(_process.cwd.call(void 0, ), _path2.default.dirname(resolvedConfig.build.outDir));
|
|
210
216
|
logger.info(`create package.json and exec "npm install"`);
|
|
@@ -335,12 +341,7 @@ function preMergeOptions(options) {
|
|
|
335
341
|
format,
|
|
336
342
|
clean: true,
|
|
337
343
|
dts: false,
|
|
338
|
-
treeshake: !!isDev
|
|
339
|
-
outExtension({ format: format2 }) {
|
|
340
|
-
return {
|
|
341
|
-
js: format2 === "esm" ? ".mjs" : `.js`
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
+
treeshake: !!isDev
|
|
344
345
|
};
|
|
345
346
|
const opts = _lodashmerge2.default.call(void 0,
|
|
346
347
|
{
|
|
@@ -351,8 +352,14 @@ function preMergeOptions(options) {
|
|
|
351
352
|
...electron2
|
|
352
353
|
},
|
|
353
354
|
preload: {
|
|
354
|
-
...electron2
|
|
355
|
-
|
|
355
|
+
...electron2,
|
|
356
|
+
outExtension({ format: format2 }) {
|
|
357
|
+
return {
|
|
358
|
+
js: format2 === "esm" ? ".mjs" : `.js`
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
builder: false
|
|
356
363
|
},
|
|
357
364
|
_lodashclonedeep2.default.call(void 0, options)
|
|
358
365
|
);
|
|
@@ -454,12 +461,11 @@ ${env}`);
|
|
|
454
461
|
});
|
|
455
462
|
},
|
|
456
463
|
async closeBundle() {
|
|
457
|
-
var _a;
|
|
458
464
|
if (isServer) {
|
|
459
465
|
return;
|
|
460
466
|
}
|
|
461
467
|
await runBuild(opts);
|
|
462
|
-
if (opts.recommended &&
|
|
468
|
+
if (opts.recommended && opts.builder) {
|
|
463
469
|
await runElectronBuilder(opts, resolvedConfig);
|
|
464
470
|
}
|
|
465
471
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -70,7 +70,7 @@ function readJson(path3) {
|
|
|
70
70
|
function writeJson(path3, data) {
|
|
71
71
|
fs.writeFileSync(path3, JSON.stringify(data, null, 2), "utf8");
|
|
72
72
|
}
|
|
73
|
-
function exec(command, args, options) {
|
|
73
|
+
function exec(command, args = [], options) {
|
|
74
74
|
return spawnSync(command, args, Object.assign({ encoding: "utf8" }, options));
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -130,6 +130,9 @@ function getBuilderConfig(options, resolvedConfig) {
|
|
|
130
130
|
deleteAppDataOnUninstall: false
|
|
131
131
|
}
|
|
132
132
|
};
|
|
133
|
+
if (typeof options.builder == "boolean") {
|
|
134
|
+
return config;
|
|
135
|
+
}
|
|
133
136
|
const { appId, productName } = options.builder || {};
|
|
134
137
|
return merge(config, { appId, productName }, (_a = options.builder) == null ? void 0 : _a.builderConfig);
|
|
135
138
|
}
|
|
@@ -204,6 +207,9 @@ function createPkg(options, resolvedConfig) {
|
|
|
204
207
|
return newPkg;
|
|
205
208
|
}
|
|
206
209
|
async function runElectronBuilder(options, resolvedConfig) {
|
|
210
|
+
if (typeof options.builder == "boolean" && options.builder == false) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
207
213
|
logger.info("building electron app...");
|
|
208
214
|
const DIST_PATH = path.join(cwd(), path.dirname(resolvedConfig.build.outDir));
|
|
209
215
|
logger.info(`create package.json and exec "npm install"`);
|
|
@@ -334,12 +340,7 @@ function preMergeOptions(options) {
|
|
|
334
340
|
format,
|
|
335
341
|
clean: true,
|
|
336
342
|
dts: false,
|
|
337
|
-
treeshake: !!isDev
|
|
338
|
-
outExtension({ format: format2 }) {
|
|
339
|
-
return {
|
|
340
|
-
js: format2 === "esm" ? ".mjs" : `.js`
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
+
treeshake: !!isDev
|
|
343
344
|
};
|
|
344
345
|
const opts = merge2(
|
|
345
346
|
{
|
|
@@ -350,8 +351,14 @@ function preMergeOptions(options) {
|
|
|
350
351
|
...electron2
|
|
351
352
|
},
|
|
352
353
|
preload: {
|
|
353
|
-
...electron2
|
|
354
|
-
|
|
354
|
+
...electron2,
|
|
355
|
+
outExtension({ format: format2 }) {
|
|
356
|
+
return {
|
|
357
|
+
js: format2 === "esm" ? ".mjs" : `.js`
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
builder: false
|
|
355
362
|
},
|
|
356
363
|
cloneDeep(options)
|
|
357
364
|
);
|
|
@@ -453,12 +460,11 @@ ${env}`);
|
|
|
453
460
|
});
|
|
454
461
|
},
|
|
455
462
|
async closeBundle() {
|
|
456
|
-
var _a;
|
|
457
463
|
if (isServer) {
|
|
458
464
|
return;
|
|
459
465
|
}
|
|
460
466
|
await runBuild(opts);
|
|
461
|
-
if (opts.recommended &&
|
|
467
|
+
if (opts.recommended && opts.builder) {
|
|
462
468
|
await runElectronBuilder(opts, resolvedConfig);
|
|
463
469
|
}
|
|
464
470
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomjs/vite-plugin-electron",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "A simple vite plugin for electron, supports esm/cjs, support esm in electron v28+",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"lint-staged": "^15.2.0",
|
|
74
74
|
"np": "^9.2.0",
|
|
75
75
|
"npm-run-all": "^4.1.5",
|
|
76
|
-
"prettier": "^3.1.
|
|
76
|
+
"prettier": "^3.1.1",
|
|
77
77
|
"rimraf": "^5.0.5",
|
|
78
78
|
"stylelint": "^15.11.0",
|
|
79
79
|
"tsx": "^4.6.2",
|