vue-cli-plugin-electron-haunv 1.0.3 → 1.0.4
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/bin/dev-runner.js +28 -35
- package/generator/index.js +21 -1
- package/generator/template/electron/main.js +9 -9
- package/index.js +1 -8
- package/package.json +6 -11
- package/bin/hot-reload.js +0 -1
package/bin/dev-runner.js
CHANGED
|
@@ -7,43 +7,14 @@ const electron = require("electron")
|
|
|
7
7
|
|
|
8
8
|
let electronProcess
|
|
9
9
|
let port
|
|
10
|
-
let reloadTimeout
|
|
11
|
-
|
|
12
|
-
function startElectron() {
|
|
13
|
-
|
|
14
|
-
electronProcess = spawn(
|
|
15
|
-
electron,
|
|
16
|
-
["."],
|
|
17
|
-
{
|
|
18
|
-
stdio: "inherit",
|
|
19
|
-
env: {
|
|
20
|
-
...process.env,
|
|
21
|
-
VITE_DEV_SERVER_URL: `http://localhost:${port}`
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function restartElectron() {
|
|
29
|
-
|
|
30
|
-
clearTimeout(reloadTimeout)
|
|
31
|
-
|
|
32
|
-
reloadTimeout = setTimeout(() => {
|
|
33
|
-
if (electronProcess) {
|
|
34
|
-
electronProcess.kill()
|
|
35
|
-
startElectron()
|
|
36
|
-
}
|
|
37
|
-
}, 300)
|
|
38
|
-
|
|
39
|
-
}
|
|
40
10
|
|
|
41
11
|
async function run() {
|
|
42
12
|
|
|
43
13
|
port = await getPort({
|
|
44
|
-
port: [8080, 8081, 8082
|
|
14
|
+
port: [8080, 8081, 8082]
|
|
45
15
|
})
|
|
46
16
|
|
|
17
|
+
// chạy vue dev server
|
|
47
18
|
spawn(
|
|
48
19
|
"npm",
|
|
49
20
|
["run", "serve", "--", "--port", port],
|
|
@@ -53,19 +24,41 @@ async function run() {
|
|
|
53
24
|
}
|
|
54
25
|
)
|
|
55
26
|
|
|
27
|
+
// đợi vue ready
|
|
56
28
|
await waitOn({
|
|
57
29
|
resources: [`http://localhost:${port}`]
|
|
58
30
|
})
|
|
59
31
|
|
|
32
|
+
// chạy electron
|
|
60
33
|
startElectron()
|
|
61
34
|
|
|
35
|
+
// hot reload electron
|
|
62
36
|
chokidar
|
|
63
|
-
.watch(["electron"], {
|
|
64
|
-
|
|
65
|
-
|
|
37
|
+
.watch(["electron"], { ignoreInitial: true })
|
|
38
|
+
.on("all", () => {
|
|
39
|
+
restartElectron()
|
|
66
40
|
})
|
|
67
|
-
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function startElectron() {
|
|
44
|
+
electronProcess = spawn(
|
|
45
|
+
electron,
|
|
46
|
+
["."],
|
|
47
|
+
{
|
|
48
|
+
stdio: "inherit",
|
|
49
|
+
env: {
|
|
50
|
+
...process.env,
|
|
51
|
+
DEV_SERVER_URL: `http://localhost:${port}`
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
)
|
|
55
|
+
}
|
|
68
56
|
|
|
57
|
+
function restartElectron() {
|
|
58
|
+
if (electronProcess) {
|
|
59
|
+
kill(electronProcess.pid)
|
|
60
|
+
startElectron()
|
|
61
|
+
}
|
|
69
62
|
}
|
|
70
63
|
|
|
71
64
|
run()
|
package/generator/index.js
CHANGED
|
@@ -1,29 +1,49 @@
|
|
|
1
1
|
module.exports = (api) => {
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
console.log("✅ Electron plugin applied")
|
|
4
4
|
|
|
5
5
|
api.extendPackage({
|
|
6
6
|
|
|
7
7
|
main: "electron/main.js",
|
|
8
8
|
|
|
9
|
+
scripts: {
|
|
10
|
+
"electron:dev": "node node_modules/vue-cli-plugin-electron-haunv/bin/dev-runner.js",
|
|
11
|
+
"electron:build": "npm run build && electron-builder"
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
devDependencies: {
|
|
15
|
+
electron: "^latest",
|
|
16
|
+
"electron-builder": "^latest"
|
|
17
|
+
},
|
|
18
|
+
|
|
9
19
|
build: {
|
|
10
20
|
appId: "com.haunv.app",
|
|
11
21
|
productName: "MyApp",
|
|
22
|
+
|
|
12
23
|
directories: {
|
|
13
24
|
output: "dist_electron"
|
|
14
25
|
},
|
|
26
|
+
|
|
15
27
|
files: [
|
|
16
28
|
"dist/**/*",
|
|
17
29
|
"electron/**/*"
|
|
18
30
|
],
|
|
31
|
+
|
|
19
32
|
win: {
|
|
20
33
|
target: [
|
|
21
34
|
"nsis",
|
|
22
35
|
"portable"
|
|
23
36
|
]
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
nsis: {
|
|
40
|
+
oneClick: false,
|
|
41
|
+
allowToChangeInstallationDirectory: true
|
|
24
42
|
}
|
|
25
43
|
}
|
|
26
44
|
|
|
27
45
|
})
|
|
28
46
|
|
|
47
|
+
api.render('./template')
|
|
48
|
+
|
|
29
49
|
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
const { app, BrowserWindow } = require("electron")
|
|
2
|
+
const path = require("path")
|
|
2
3
|
|
|
3
|
-
let
|
|
4
|
+
let win
|
|
4
5
|
|
|
5
6
|
function createWindow() {
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
win = new BrowserWindow({
|
|
8
9
|
width: 1200,
|
|
9
10
|
height: 800,
|
|
10
11
|
webPreferences: {
|
|
11
|
-
preload:
|
|
12
|
-
contextIsolation: true
|
|
13
|
-
nodeIntegration: false
|
|
12
|
+
preload: path.join(__dirname, "preload.js"),
|
|
13
|
+
contextIsolation: true
|
|
14
14
|
}
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
if (process.env.
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
if (process.env.DEV_SERVER_URL) {
|
|
18
|
+
win.loadURL(process.env.DEV_SERVER_URL)
|
|
19
|
+
win.webContents.openDevTools()
|
|
20
20
|
} else {
|
|
21
|
-
|
|
21
|
+
win.loadFile(path.join(__dirname, "../dist/index.html"))
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
}
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-cli-plugin-electron-haunv",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
|
|
@@ -10,15 +10,10 @@
|
|
|
10
10
|
"index.js"
|
|
11
11
|
],
|
|
12
12
|
|
|
13
|
-
"dependencies": {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"concurrently": "latest",
|
|
19
|
-
"wait-on": "latest",
|
|
20
|
-
"chokidar": "latest",
|
|
21
|
-
"tree-kill": "latest",
|
|
22
|
-
"get-port": "latest"
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"wait-on": "^7.2.0",
|
|
15
|
+
"chokidar": "^3.5.3",
|
|
16
|
+
"tree-kill": "^1.2.2",
|
|
17
|
+
"get-port": "^7.0.0"
|
|
23
18
|
}
|
|
24
19
|
}
|
package/bin/hot-reload.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// custom reload
|