vue-cli-plugin-electron-haunv 1.0.1 → 1.0.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/bin/dev-runner.js +71 -0
- package/bin/hot-reload.js +1 -0
- package/generator/index.js +5 -22
- package/generator/template/electron/main.js +15 -35
- package/generator/template/electron/preload.js +2 -6
- package/index.js +8 -3
- package/package.json +17 -16
- package/generator/template/electron/dev-runner.js +0 -56
- package/generator/template/electron/hot-reload.js +0 -17
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const { spawn } = require("child_process")
|
|
2
|
+
const waitOn = require("wait-on")
|
|
3
|
+
const getPort = require("get-port").default
|
|
4
|
+
const chokidar = require("chokidar")
|
|
5
|
+
const kill = require("tree-kill")
|
|
6
|
+
const electron = require("electron")
|
|
7
|
+
|
|
8
|
+
let electronProcess
|
|
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
|
+
|
|
41
|
+
async function run() {
|
|
42
|
+
|
|
43
|
+
port = await getPort({
|
|
44
|
+
port: [8080, 8081, 8082, 8083]
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
spawn(
|
|
48
|
+
"npm",
|
|
49
|
+
["run", "serve", "--", "--port", port],
|
|
50
|
+
{
|
|
51
|
+
stdio: "inherit",
|
|
52
|
+
shell: true
|
|
53
|
+
}
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
await waitOn({
|
|
57
|
+
resources: [`http://localhost:${port}`]
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
startElectron()
|
|
61
|
+
|
|
62
|
+
chokidar
|
|
63
|
+
.watch(["electron"], {
|
|
64
|
+
ignored: /node_modules/,
|
|
65
|
+
ignoreInitial: true
|
|
66
|
+
})
|
|
67
|
+
.on("all", restartElectron)
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
run()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// custom reload
|
package/generator/index.js
CHANGED
|
@@ -1,46 +1,29 @@
|
|
|
1
|
-
module.exports = api => {
|
|
1
|
+
module.exports = (api) => {
|
|
2
|
+
|
|
3
|
+
api.render('./template')
|
|
2
4
|
|
|
3
5
|
api.extendPackage({
|
|
4
6
|
|
|
5
7
|
main: "electron/main.js",
|
|
6
8
|
|
|
7
|
-
scripts: {
|
|
8
|
-
|
|
9
|
-
"electron:dev": "node electron/dev-runner.js",
|
|
10
|
-
|
|
11
|
-
"electron:build":
|
|
12
|
-
"npm run build && electron-builder"
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
|
|
16
9
|
build: {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
productName: "VueElectronApp",
|
|
21
|
-
|
|
10
|
+
appId: "com.haunv.app",
|
|
11
|
+
productName: "MyApp",
|
|
22
12
|
directories: {
|
|
23
13
|
output: "dist_electron"
|
|
24
14
|
},
|
|
25
|
-
|
|
26
15
|
files: [
|
|
27
16
|
"dist/**/*",
|
|
28
17
|
"electron/**/*"
|
|
29
18
|
],
|
|
30
|
-
|
|
31
|
-
asar: true,
|
|
32
|
-
|
|
33
19
|
win: {
|
|
34
20
|
target: [
|
|
35
21
|
"nsis",
|
|
36
22
|
"portable"
|
|
37
23
|
]
|
|
38
24
|
}
|
|
39
|
-
|
|
40
25
|
}
|
|
41
26
|
|
|
42
27
|
})
|
|
43
28
|
|
|
44
|
-
api.render("./template")
|
|
45
|
-
|
|
46
29
|
}
|
|
@@ -1,50 +1,30 @@
|
|
|
1
1
|
const { app, BrowserWindow } = require("electron")
|
|
2
|
-
const path = require("path")
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
const { VUEJS_DEVTOOLS } = require("electron-devtools-installer")
|
|
3
|
+
let mainWindow
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const isDev = !app.isPackaged
|
|
10
|
-
const port = process.argv[2] || 8080
|
|
11
|
-
|
|
12
|
-
let win
|
|
13
|
-
|
|
14
|
-
async function createWindow() {
|
|
15
|
-
|
|
16
|
-
win = new BrowserWindow({
|
|
5
|
+
function createWindow() {
|
|
17
6
|
|
|
7
|
+
mainWindow = new BrowserWindow({
|
|
18
8
|
width: 1200,
|
|
19
9
|
height: 800,
|
|
20
|
-
|
|
21
10
|
webPreferences: {
|
|
22
|
-
preload: path.join(__dirname, "preload.js"),
|
|
23
|
-
contextIsolation: true
|
|
11
|
+
preload: require("path").join(__dirname, "preload.js"),
|
|
12
|
+
contextIsolation: true,
|
|
13
|
+
nodeIntegration: false
|
|
24
14
|
}
|
|
25
|
-
|
|
26
15
|
})
|
|
27
16
|
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
win.webContents.openDevTools()
|
|
33
|
-
|
|
34
|
-
enableHotReload(win)
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
await installExtension(VUEJS_DEVTOOLS)
|
|
38
|
-
} catch { }
|
|
39
|
-
|
|
17
|
+
if (process.env.VITE_DEV_SERVER_URL) {
|
|
18
|
+
mainWindow.loadURL(process.env.VITE_DEV_SERVER_URL)
|
|
19
|
+
mainWindow.webContents.openDevTools()
|
|
40
20
|
} else {
|
|
41
|
-
|
|
42
|
-
win.loadFile(
|
|
43
|
-
path.join(__dirname, "../dist/index.html")
|
|
44
|
-
)
|
|
45
|
-
|
|
21
|
+
mainWindow.loadFile("dist/index.html")
|
|
46
22
|
}
|
|
47
23
|
|
|
48
24
|
}
|
|
49
25
|
|
|
50
|
-
app.whenReady().then(createWindow)
|
|
26
|
+
app.whenReady().then(createWindow)
|
|
27
|
+
|
|
28
|
+
app.on("window-all-closed", () => {
|
|
29
|
+
if (process.platform !== "darwin") app.quit()
|
|
30
|
+
})
|
package/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
module.exports = api => {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
module.exports = (api) => {
|
|
2
|
+
api.extendPackage({
|
|
3
|
+
scripts: {
|
|
4
|
+
"electron:dev": "node node_modules/vue-cli-plugin-electron-haunv/bin/dev-runner.js",
|
|
5
|
+
"electron:build": "electron-builder"
|
|
6
|
+
}
|
|
7
|
+
})
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-cli-plugin-electron-haunv",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "1.0.3",
|
|
5
4
|
"main": "index.js",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
|
|
7
|
+
"files": [
|
|
8
|
+
"generator",
|
|
9
|
+
"bin",
|
|
10
|
+
"index.js"
|
|
11
|
+
],
|
|
12
|
+
|
|
13
|
+
"dependencies": {},
|
|
14
|
+
|
|
15
|
+
"devDependencies": {
|
|
16
16
|
"electron": "latest",
|
|
17
17
|
"electron-builder": "latest",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
18
|
+
"concurrently": "latest",
|
|
19
|
+
"wait-on": "latest",
|
|
20
|
+
"chokidar": "latest",
|
|
20
21
|
"tree-kill": "latest",
|
|
21
|
-
"
|
|
22
|
+
"get-port": "latest"
|
|
22
23
|
}
|
|
23
|
-
}
|
|
24
|
+
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
const { spawn } = require("child_process")
|
|
2
|
-
const waitOn = require("wait-on")
|
|
3
|
-
const getPort = require("get-port").default
|
|
4
|
-
const chokidar = require("chokidar")
|
|
5
|
-
const kill = require("tree-kill")
|
|
6
|
-
|
|
7
|
-
let electronProcess
|
|
8
|
-
let port
|
|
9
|
-
|
|
10
|
-
function startElectron() {
|
|
11
|
-
|
|
12
|
-
electronProcess = spawn(
|
|
13
|
-
"npx",
|
|
14
|
-
["electron", ".", port],
|
|
15
|
-
{ stdio: "inherit" }
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function restartElectron() {
|
|
21
|
-
|
|
22
|
-
if (electronProcess) {
|
|
23
|
-
|
|
24
|
-
kill(electronProcess.pid)
|
|
25
|
-
|
|
26
|
-
startElectron()
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async function run() {
|
|
33
|
-
|
|
34
|
-
port = await getPort({
|
|
35
|
-
port: [8080, 8081, 8082, 8083]
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
spawn(
|
|
39
|
-
"npm",
|
|
40
|
-
["run", "serve", "--", "--port", port],
|
|
41
|
-
{ stdio: "inherit" }
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
await waitOn({
|
|
45
|
-
resources: [`http://localhost:${port}`]
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
startElectron()
|
|
49
|
-
|
|
50
|
-
chokidar
|
|
51
|
-
.watch(["electron"])
|
|
52
|
-
.on("change", restartElectron)
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
run()
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const chokidar = require("chokidar")
|
|
2
|
-
|
|
3
|
-
function enableHotReload(win) {
|
|
4
|
-
|
|
5
|
-
chokidar.watch([
|
|
6
|
-
__dirname + "/main.js"
|
|
7
|
-
]).on("change", () => {
|
|
8
|
-
|
|
9
|
-
if (win && !win.isDestroyed()) {
|
|
10
|
-
win.reload()
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
module.exports = enableHotReload
|