@ubean/integrations 0.6.0 → 0.6.1-beta.3
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/dist/electron/index.d.ts +24 -0
- package/dist/electron/index.js +59 -3
- package/package.json +5 -5
package/dist/electron/index.d.ts
CHANGED
|
@@ -6,6 +6,30 @@ export declare const DEFAULT_MAIN_ENTRY = "electron/main.ts";
|
|
|
6
6
|
/** preload 脚本入口默认值 */
|
|
7
7
|
export declare const DEFAULT_PRELOAD_INPUT = "electron/preload.ts";
|
|
8
8
|
//#endregion
|
|
9
|
+
//#region src/electron/index-html-cleanup.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* `vite-plugin-electron` 的 `MOCK_INDEX_HTML` 的副本,逐字节一致。
|
|
12
|
+
*
|
|
13
|
+
* 不能从包里 import —— 它只作为模块内的局部常量存在(未导出),所以这里复制一份。
|
|
14
|
+
* 比对用**内容相等**而非文件名,这样用户自己的 `index.html` 永远不会被删。
|
|
15
|
+
*/
|
|
16
|
+
export declare const VITE_PLUGIN_ELECTRON_MOCK_INDEX_HTML = "<!doctype html>\n<html lang=\"en\">\n <head>\n <title>vite-plugin-electron</title>\n </head>\n <body>\n <div>An entry file for electron renderer process.</div>\n </body>\n</html>";
|
|
17
|
+
/** 本插件名,便于在 Vite 插件列表里识别。 */
|
|
18
|
+
export declare const ELECTRON_INDEX_CLEANUP_PLUGIN_NAME = "ubean:electron:index-html-cleanup";
|
|
19
|
+
/**
|
|
20
|
+
* 内容是否就是 `vite-plugin-electron` 的残留 mock。
|
|
21
|
+
*
|
|
22
|
+
* 完全相等时立即为真;否则要求两个标记串都在,用来兜住换行/尾随空白的差异。
|
|
23
|
+
*/
|
|
24
|
+
export declare function isVitePluginElectronMock(content: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 创建清理插件。
|
|
27
|
+
*
|
|
28
|
+
* 只在 `serve`(dev)下生效 —— `build` 路径没有这个 mock(`closeBundle` 会删,且
|
|
29
|
+
* `resolveInput` 在产物构建里拿到的是真实的 `environments` 入口)。
|
|
30
|
+
*/
|
|
31
|
+
export declare function createElectronIndexHtmlCleanupPlugin(): Plugin;
|
|
32
|
+
//#endregion
|
|
9
33
|
//#region src/electron/index.d.ts
|
|
10
34
|
/**
|
|
11
35
|
* ubean Electron Vite 插件(基于 vite-plugin-electron)
|
package/dist/electron/index.js
CHANGED
|
@@ -5,6 +5,62 @@ const DEFAULT_MAIN_ENTRY = "electron/main.ts";
|
|
|
5
5
|
/** preload 脚本入口默认值 */
|
|
6
6
|
const DEFAULT_PRELOAD_INPUT = "electron/preload.ts";
|
|
7
7
|
//#endregion
|
|
8
|
+
//#region src/electron/index-html-cleanup.ts
|
|
9
|
+
/**
|
|
10
|
+
* `vite-plugin-electron` 的 `MOCK_INDEX_HTML` 的副本,逐字节一致。
|
|
11
|
+
*
|
|
12
|
+
* 不能从包里 import —— 它只作为模块内的局部常量存在(未导出),所以这里复制一份。
|
|
13
|
+
* 比对用**内容相等**而非文件名,这样用户自己的 `index.html` 永远不会被删。
|
|
14
|
+
*/
|
|
15
|
+
const VITE_PLUGIN_ELECTRON_MOCK_INDEX_HTML = `<!doctype html>
|
|
16
|
+
<html lang="en">
|
|
17
|
+
<head>
|
|
18
|
+
<title>vite-plugin-electron</title>
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
<div>An entry file for electron renderer process.</div>
|
|
22
|
+
</body>
|
|
23
|
+
</html>`;
|
|
24
|
+
/** 本插件名,便于在 Vite 插件列表里识别。 */
|
|
25
|
+
const ELECTRON_INDEX_CLEANUP_PLUGIN_NAME = "ubean:electron:index-html-cleanup";
|
|
26
|
+
/** 该 mock 的标题特征(内容比对之外的第二道判据,避免只差一个换行就漏掉)。 */
|
|
27
|
+
const MOCK_MARKERS = ["vite-plugin-electron", "An entry file for electron renderer process."];
|
|
28
|
+
/**
|
|
29
|
+
* 内容是否就是 `vite-plugin-electron` 的残留 mock。
|
|
30
|
+
*
|
|
31
|
+
* 完全相等时立即为真;否则要求两个标记串都在,用来兜住换行/尾随空白的差异。
|
|
32
|
+
*/
|
|
33
|
+
function isVitePluginElectronMock(content) {
|
|
34
|
+
if (content === VITE_PLUGIN_ELECTRON_MOCK_INDEX_HTML) return true;
|
|
35
|
+
return MOCK_MARKERS.every((marker) => content.includes(marker));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 创建清理插件。
|
|
39
|
+
*
|
|
40
|
+
* 只在 `serve`(dev)下生效 —— `build` 路径没有这个 mock(`closeBundle` 会删,且
|
|
41
|
+
* `resolveInput` 在产物构建里拿到的是真实的 `environments` 入口)。
|
|
42
|
+
*/
|
|
43
|
+
function createElectronIndexHtmlCleanupPlugin() {
|
|
44
|
+
return {
|
|
45
|
+
name: ELECTRON_INDEX_CLEANUP_PLUGIN_NAME,
|
|
46
|
+
apply: "serve",
|
|
47
|
+
async configResolved(config) {
|
|
48
|
+
const { unlink, readFile, rm } = await import("node:fs/promises");
|
|
49
|
+
const { join } = await import("node:path");
|
|
50
|
+
const mockPath = join(config.root, "index.html");
|
|
51
|
+
let content;
|
|
52
|
+
try {
|
|
53
|
+
content = await readFile(mockPath, "utf-8");
|
|
54
|
+
} catch {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (!isVitePluginElectronMock(content)) return;
|
|
58
|
+
await unlink(mockPath).catch(() => rm(mockPath, { force: true }));
|
|
59
|
+
config.logger.info(`[ubean] 已清掉 vite-plugin-electron 写下的占位 index.html(${mockPath})—— 它不是 ubean 的入口,删掉不影响 dev server`);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
8
64
|
//#region src/electron/index.ts
|
|
9
65
|
/**
|
|
10
66
|
* ubean Electron Vite 插件(基于 vite-plugin-electron)
|
|
@@ -46,10 +102,10 @@ async function ubeanElectronPlugin(options = {}) {
|
|
|
46
102
|
};
|
|
47
103
|
if (options.renderer) electronConfig.renderer = options.renderer;
|
|
48
104
|
const plugins = await electron(electronConfig);
|
|
49
|
-
return (Array.isArray(plugins) ? plugins : [plugins]).map((p) => ({
|
|
105
|
+
return [...(Array.isArray(plugins) ? plugins : [plugins]).map((p) => ({
|
|
50
106
|
...p,
|
|
51
107
|
name: p.name?.startsWith("ubean:") ? p.name : `ubean:electron(${p.name ?? "unknown"})`
|
|
52
|
-
}));
|
|
108
|
+
})), createElectronIndexHtmlCleanupPlugin()];
|
|
53
109
|
}
|
|
54
110
|
/**
|
|
55
111
|
* 类型安全的 Electron 配置定义辅助函数(透传)
|
|
@@ -58,4 +114,4 @@ function defineElectronConfig(options) {
|
|
|
58
114
|
return options;
|
|
59
115
|
}
|
|
60
116
|
//#endregion
|
|
61
|
-
export { DEFAULT_MAIN_ENTRY, DEFAULT_PRELOAD_INPUT, ubeanElectronPlugin as default, ubeanElectronPlugin, defineElectronConfig };
|
|
117
|
+
export { DEFAULT_MAIN_ENTRY, DEFAULT_PRELOAD_INPUT, ELECTRON_INDEX_CLEANUP_PLUGIN_NAME, VITE_PLUGIN_ELECTRON_MOCK_INDEX_HTML, createElectronIndexHtmlCleanupPlugin, ubeanElectronPlugin as default, ubeanElectronPlugin, defineElectronConfig, isVitePluginElectronMock };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ubean/integrations",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1-beta.3",
|
|
4
4
|
"description": "Thin integration bundles for ubean (pwa, fonts, electron, ui, pinia)",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -36,17 +36,17 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@ubean/build": "0.6.
|
|
39
|
+
"@ubean/build": "0.6.1-beta.3",
|
|
40
40
|
"defu": "6.1.7",
|
|
41
41
|
"ohash": "^2.0.12",
|
|
42
42
|
"vite-plugin-electron": "^1.1.2",
|
|
43
|
-
"vite-plugin-pwa": "^
|
|
43
|
+
"vite-plugin-pwa": "^2.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/node": "^26.6.4",
|
|
47
47
|
"typescript": "npm:typescript-native-bridge@latest",
|
|
48
|
-
"vite": "npm:@voidzero-dev/vite-plus-core@1.
|
|
49
|
-
"vite-plus": "1.
|
|
48
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.1.0",
|
|
49
|
+
"vite-plus": "1.1.0",
|
|
50
50
|
"vue": "^3.5.43"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|