@tomjs/vite-plugin-electron 1.1.0 → 1.1.1
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 +36 -1
- package/README.zh_CN.md +36 -1
- package/env.d.ts +17 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -66,7 +66,42 @@ npm i @tomjs/vite-plugin-electron --save-dev
|
|
|
66
66
|
| | |--index.html
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
### electron
|
|
70
|
+
|
|
71
|
+
`electron/main/index.ts`
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { dirname } from 'node:path';
|
|
75
|
+
import { fileURLToPath } from 'node:url';
|
|
76
|
+
import { app, BrowserWindow } from 'electron';
|
|
77
|
+
|
|
78
|
+
// when package.json "type": module"
|
|
79
|
+
global.__dirname = dirname(fileURLToPath(import.meta.url));
|
|
80
|
+
|
|
81
|
+
const preload = join(__dirname, '../preload/index.mjs');
|
|
82
|
+
const url = process.env.APP_DEV_SERVER_URL;
|
|
83
|
+
|
|
84
|
+
async function createWindow() {
|
|
85
|
+
win = new BrowserWindow({
|
|
86
|
+
title: 'Main window',
|
|
87
|
+
width: 800,
|
|
88
|
+
height: 700,
|
|
89
|
+
webPreferences: {
|
|
90
|
+
preload,
|
|
91
|
+
nodeIntegration: true,
|
|
92
|
+
contextIsolation: false,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (isDev) {
|
|
97
|
+
win.loadURL(url);
|
|
98
|
+
} else {
|
|
99
|
+
win.loadFile(indexHtml);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
app.whenReady().then(createWindow);
|
|
104
|
+
```
|
|
70
105
|
|
|
71
106
|
### vue
|
|
72
107
|
|
package/README.zh_CN.md
CHANGED
|
@@ -66,7 +66,42 @@ npm i @tomjs/vite-plugin-electron --save-dev
|
|
|
66
66
|
| | |--index.html
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
### electron
|
|
70
|
+
|
|
71
|
+
`electron/main/index.ts`
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { dirname } from 'node:path';
|
|
75
|
+
import { fileURLToPath } from 'node:url';
|
|
76
|
+
import { app, BrowserWindow } from 'electron';
|
|
77
|
+
|
|
78
|
+
// when package.json "type": module"
|
|
79
|
+
global.__dirname = dirname(fileURLToPath(import.meta.url));
|
|
80
|
+
|
|
81
|
+
const preload = join(__dirname, '../preload/index.mjs');
|
|
82
|
+
const url = process.env.APP_DEV_SERVER_URL;
|
|
83
|
+
|
|
84
|
+
async function createWindow() {
|
|
85
|
+
win = new BrowserWindow({
|
|
86
|
+
title: 'Main window',
|
|
87
|
+
width: 800,
|
|
88
|
+
height: 700,
|
|
89
|
+
webPreferences: {
|
|
90
|
+
preload,
|
|
91
|
+
nodeIntegration: true,
|
|
92
|
+
contextIsolation: false,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (isDev) {
|
|
97
|
+
win.loadURL(url);
|
|
98
|
+
} else {
|
|
99
|
+
win.loadFile(indexHtml);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
app.whenReady().then(createWindow);
|
|
104
|
+
```
|
|
70
105
|
|
|
71
106
|
### vue
|
|
72
107
|
|
package/env.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fix code hint
|
|
3
|
+
*/
|
|
4
|
+
type UnionType<T> = T | (string & {});
|
|
5
|
+
|
|
6
|
+
declare namespace NodeJS {
|
|
7
|
+
interface ProcessEnv {
|
|
8
|
+
/**
|
|
9
|
+
* Node.js environment
|
|
10
|
+
*/
|
|
11
|
+
NODE_ENV: UnionType<'development' | 'test' | 'production'>;
|
|
12
|
+
/**
|
|
13
|
+
* The url of the dev server.
|
|
14
|
+
*/
|
|
15
|
+
readonly APP_DEV_SERVER_URL: string;
|
|
16
|
+
}
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomjs/vite-plugin-electron",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "A simple vite plugin for electron, supports esm/cjs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
|
-
"dist"
|
|
27
|
+
"dist",
|
|
28
|
+
"env.d.ts"
|
|
28
29
|
],
|
|
29
30
|
"engines": {
|
|
30
31
|
"node": ">=16"
|