@tomjs/vite-plugin-electron 1.6.0 → 1.7.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 +4 -4
- package/README.zh_CN.md +4 -4
- package/dist/index.js +32 -26
- package/dist/index.mjs +32 -26
- package/env.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -96,7 +96,7 @@ import { app, BrowserWindow } from 'electron';
|
|
|
96
96
|
global.__dirname = dirname(fileURLToPath(import.meta.url));
|
|
97
97
|
|
|
98
98
|
const preload = join(__dirname, '../preload/index.mjs');
|
|
99
|
-
const url = process.env.
|
|
99
|
+
const url = process.env.VITE_DEV_SERVER_URL;
|
|
100
100
|
|
|
101
101
|
async function createWindow() {
|
|
102
102
|
win = new BrowserWindow({
|
|
@@ -314,9 +314,9 @@ const config = {
|
|
|
314
314
|
|
|
315
315
|
Electron `main process` and `renderer process` use.
|
|
316
316
|
|
|
317
|
-
| Variable
|
|
318
|
-
|
|
|
319
|
-
|
|
|
317
|
+
| Variable | Description |
|
|
318
|
+
| --------------------- | -------------------------- |
|
|
319
|
+
| `VITE_DEV_SERVER_URL` | The url of the dev server. |
|
|
320
320
|
|
|
321
321
|
## Debug
|
|
322
322
|
|
package/README.zh_CN.md
CHANGED
|
@@ -96,7 +96,7 @@ import { app, BrowserWindow } from 'electron';
|
|
|
96
96
|
global.__dirname = dirname(fileURLToPath(import.meta.url));
|
|
97
97
|
|
|
98
98
|
const preload = join(__dirname, '../preload/index.mjs');
|
|
99
|
-
const url = process.env.
|
|
99
|
+
const url = process.env.VITE_DEV_SERVER_URL;
|
|
100
100
|
|
|
101
101
|
async function createWindow() {
|
|
102
102
|
win = new BrowserWindow({
|
|
@@ -313,9 +313,9 @@ const config = {
|
|
|
313
313
|
|
|
314
314
|
Electron `main process` 和 `renderer process` 使用。
|
|
315
315
|
|
|
316
|
-
| 变量
|
|
317
|
-
|
|
|
318
|
-
|
|
|
316
|
+
| 变量 | 描述 |
|
|
317
|
+
| --------------------- | --------------------- |
|
|
318
|
+
| `VITE_DEV_SERVER_URL` | Vite 开发服务器的 URL |
|
|
319
319
|
|
|
320
320
|
## 调试
|
|
321
321
|
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
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 _process = require('process');
|
|
4
3
|
var _lodashclonedeep = require('lodash.clonedeep'); var _lodashclonedeep2 = _interopRequireDefault(_lodashclonedeep);
|
|
5
4
|
var _lodashmerge = require('lodash.merge'); var _lodashmerge2 = _interopRequireDefault(_lodashmerge);
|
|
6
5
|
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
@@ -8,7 +7,7 @@ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
|
8
7
|
// src/builder.ts
|
|
9
8
|
var _os = require('os'); var _os2 = _interopRequireDefault(_os);
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
var _process = require('process');
|
|
12
11
|
|
|
13
12
|
var _shelljs = require('shelljs'); var _shelljs2 = _interopRequireDefault(_shelljs);
|
|
14
13
|
|
|
@@ -18,7 +17,6 @@ var _kolorist = require('kolorist');
|
|
|
18
17
|
|
|
19
18
|
// src/constants.ts
|
|
20
19
|
var PLUGIN_NAME = "@tomjs:electron";
|
|
21
|
-
var PACKAGE_NAME = "@tomjs/vite-plugin-electron";
|
|
22
20
|
|
|
23
21
|
// src/logger.ts
|
|
24
22
|
var Logger = class {
|
|
@@ -71,6 +69,30 @@ function readJson(path3) {
|
|
|
71
69
|
function writeJson(path3, data) {
|
|
72
70
|
_fs2.default.writeFileSync(path3, JSON.stringify(data, null, 2), "utf8");
|
|
73
71
|
}
|
|
72
|
+
function resolveHostname(hostname) {
|
|
73
|
+
const loopbackHosts = /* @__PURE__ */ new Set([
|
|
74
|
+
"localhost",
|
|
75
|
+
"127.0.0.1",
|
|
76
|
+
"::1",
|
|
77
|
+
"0000:0000:0000:0000:0000:0000:0000:0001"
|
|
78
|
+
]);
|
|
79
|
+
const wildcardHosts = /* @__PURE__ */ new Set(["0.0.0.0", "::", "0000:0000:0000:0000:0000:0000:0000:0000"]);
|
|
80
|
+
return loopbackHosts.has(hostname) || wildcardHosts.has(hostname) ? "localhost" : hostname;
|
|
81
|
+
}
|
|
82
|
+
function resolveServerUrl(server) {
|
|
83
|
+
const addressInfo = server.httpServer.address();
|
|
84
|
+
const isAddressInfo = (x) => x == null ? void 0 : x.address;
|
|
85
|
+
if (isAddressInfo(addressInfo)) {
|
|
86
|
+
const { address, port } = addressInfo;
|
|
87
|
+
const hostname = resolveHostname(address);
|
|
88
|
+
const options = server.config.server;
|
|
89
|
+
const protocol = options.https ? "https" : "http";
|
|
90
|
+
const devBase = server.config.base;
|
|
91
|
+
const path3 = typeof options.open === "string" ? options.open : devBase;
|
|
92
|
+
const url = path3.startsWith("http") ? path3 : `${protocol}://${hostname}:${port}${path3}`;
|
|
93
|
+
return url;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
74
96
|
|
|
75
97
|
// src/builder.ts
|
|
76
98
|
var logger = createLogger();
|
|
@@ -427,17 +449,7 @@ function useElectronPlugin(options) {
|
|
|
427
449
|
opts.main.minify ??= true;
|
|
428
450
|
opts.preload.minify ??= true;
|
|
429
451
|
}
|
|
430
|
-
let envPrefix = config.envPrefix;
|
|
431
|
-
if (!envPrefix) {
|
|
432
|
-
envPrefix = ["VITE_"];
|
|
433
|
-
} else if (typeof envPrefix === "string") {
|
|
434
|
-
envPrefix = [envPrefix];
|
|
435
|
-
}
|
|
436
|
-
if (!envPrefix.includes("APP_")) {
|
|
437
|
-
envPrefix.push("APP_");
|
|
438
|
-
}
|
|
439
452
|
return {
|
|
440
|
-
envPrefix: [...new Set(envPrefix)],
|
|
441
453
|
build: {
|
|
442
454
|
outDir
|
|
443
455
|
}
|
|
@@ -454,19 +466,13 @@ function useElectronPlugin(options) {
|
|
|
454
466
|
return;
|
|
455
467
|
}
|
|
456
468
|
server.httpServer.on("listening", async () => {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
if (!_fs2.default.existsSync(DEBUG_PATH)) {
|
|
465
|
-
_fs.mkdirSync.call(void 0, DEBUG_PATH, { recursive: true });
|
|
466
|
-
}
|
|
467
|
-
const env = Object.keys(process.env).filter((s) => s.startsWith("APP_") || s.startsWith("VITE_")).map((s) => `${s}=${process.env[s]}`).join("\n");
|
|
468
|
-
_fs.writeFileSync.call(void 0, _path2.default.join(DEBUG_PATH, ".env"), `NODE_ENV=development
|
|
469
|
-
${env}`);
|
|
469
|
+
const env = {
|
|
470
|
+
NODE_ENV: server.config.mode || "development",
|
|
471
|
+
VITE_DEV_SERVER_URL: resolveServerUrl(server)
|
|
472
|
+
};
|
|
473
|
+
["main", "preload"].forEach((prop) => {
|
|
474
|
+
opts[prop].env = env;
|
|
475
|
+
});
|
|
470
476
|
await runServe(opts, server);
|
|
471
477
|
});
|
|
472
478
|
},
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import fs2
|
|
3
|
-
import { cwd as cwd2 } from "process";
|
|
2
|
+
import fs2 from "fs";
|
|
4
3
|
import cloneDeep from "lodash.clonedeep";
|
|
5
4
|
import merge2 from "lodash.merge";
|
|
6
5
|
import path2 from "path";
|
|
@@ -18,7 +17,6 @@ import { blue, gray, green, red, yellow } from "kolorist";
|
|
|
18
17
|
|
|
19
18
|
// src/constants.ts
|
|
20
19
|
var PLUGIN_NAME = "@tomjs:electron";
|
|
21
|
-
var PACKAGE_NAME = "@tomjs/vite-plugin-electron";
|
|
22
20
|
|
|
23
21
|
// src/logger.ts
|
|
24
22
|
var Logger = class {
|
|
@@ -70,6 +68,30 @@ function readJson(path3) {
|
|
|
70
68
|
function writeJson(path3, data) {
|
|
71
69
|
fs.writeFileSync(path3, JSON.stringify(data, null, 2), "utf8");
|
|
72
70
|
}
|
|
71
|
+
function resolveHostname(hostname) {
|
|
72
|
+
const loopbackHosts = /* @__PURE__ */ new Set([
|
|
73
|
+
"localhost",
|
|
74
|
+
"127.0.0.1",
|
|
75
|
+
"::1",
|
|
76
|
+
"0000:0000:0000:0000:0000:0000:0000:0001"
|
|
77
|
+
]);
|
|
78
|
+
const wildcardHosts = /* @__PURE__ */ new Set(["0.0.0.0", "::", "0000:0000:0000:0000:0000:0000:0000:0000"]);
|
|
79
|
+
return loopbackHosts.has(hostname) || wildcardHosts.has(hostname) ? "localhost" : hostname;
|
|
80
|
+
}
|
|
81
|
+
function resolveServerUrl(server) {
|
|
82
|
+
const addressInfo = server.httpServer.address();
|
|
83
|
+
const isAddressInfo = (x) => x == null ? void 0 : x.address;
|
|
84
|
+
if (isAddressInfo(addressInfo)) {
|
|
85
|
+
const { address, port } = addressInfo;
|
|
86
|
+
const hostname = resolveHostname(address);
|
|
87
|
+
const options = server.config.server;
|
|
88
|
+
const protocol = options.https ? "https" : "http";
|
|
89
|
+
const devBase = server.config.base;
|
|
90
|
+
const path3 = typeof options.open === "string" ? options.open : devBase;
|
|
91
|
+
const url = path3.startsWith("http") ? path3 : `${protocol}://${hostname}:${port}${path3}`;
|
|
92
|
+
return url;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
73
95
|
|
|
74
96
|
// src/builder.ts
|
|
75
97
|
var logger = createLogger();
|
|
@@ -426,17 +448,7 @@ function useElectronPlugin(options) {
|
|
|
426
448
|
opts.main.minify ??= true;
|
|
427
449
|
opts.preload.minify ??= true;
|
|
428
450
|
}
|
|
429
|
-
let envPrefix = config.envPrefix;
|
|
430
|
-
if (!envPrefix) {
|
|
431
|
-
envPrefix = ["VITE_"];
|
|
432
|
-
} else if (typeof envPrefix === "string") {
|
|
433
|
-
envPrefix = [envPrefix];
|
|
434
|
-
}
|
|
435
|
-
if (!envPrefix.includes("APP_")) {
|
|
436
|
-
envPrefix.push("APP_");
|
|
437
|
-
}
|
|
438
451
|
return {
|
|
439
|
-
envPrefix: [...new Set(envPrefix)],
|
|
440
452
|
build: {
|
|
441
453
|
outDir
|
|
442
454
|
}
|
|
@@ -453,19 +465,13 @@ function useElectronPlugin(options) {
|
|
|
453
465
|
return;
|
|
454
466
|
}
|
|
455
467
|
server.httpServer.on("listening", async () => {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
if (!fs2.existsSync(DEBUG_PATH)) {
|
|
464
|
-
mkdirSync(DEBUG_PATH, { recursive: true });
|
|
465
|
-
}
|
|
466
|
-
const env = Object.keys(process.env).filter((s) => s.startsWith("APP_") || s.startsWith("VITE_")).map((s) => `${s}=${process.env[s]}`).join("\n");
|
|
467
|
-
writeFileSync(path2.join(DEBUG_PATH, ".env"), `NODE_ENV=development
|
|
468
|
-
${env}`);
|
|
468
|
+
const env = {
|
|
469
|
+
NODE_ENV: server.config.mode || "development",
|
|
470
|
+
VITE_DEV_SERVER_URL: resolveServerUrl(server)
|
|
471
|
+
};
|
|
472
|
+
["main", "preload"].forEach((prop) => {
|
|
473
|
+
opts[prop].env = env;
|
|
474
|
+
});
|
|
469
475
|
await runServe(opts, server);
|
|
470
476
|
});
|
|
471
477
|
},
|
package/env.d.ts
CHANGED