vue-cli-plugin-electron-haunv 1.0.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/generator/index.js +46 -0
- package/generator/template/electron/dev-runner.js +56 -0
- package/generator/template/electron/hot-reload.js +17 -0
- package/generator/template/electron/main.js +50 -0
- package/generator/template/electron/preload.js +9 -0
- package/index.js +3 -0
- package/package.json +23 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module.exports = api => {
|
|
2
|
+
|
|
3
|
+
api.extendPackage({
|
|
4
|
+
|
|
5
|
+
main: "electron/main.js",
|
|
6
|
+
|
|
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
|
+
build: {
|
|
17
|
+
|
|
18
|
+
appId: "com.vue.electron.app",
|
|
19
|
+
|
|
20
|
+
productName: "VueElectronApp",
|
|
21
|
+
|
|
22
|
+
directories: {
|
|
23
|
+
output: "dist_electron"
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
files: [
|
|
27
|
+
"dist/**/*",
|
|
28
|
+
"electron/**/*"
|
|
29
|
+
],
|
|
30
|
+
|
|
31
|
+
asar: true,
|
|
32
|
+
|
|
33
|
+
win: {
|
|
34
|
+
target: [
|
|
35
|
+
"nsis",
|
|
36
|
+
"portable"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
api.render("./template")
|
|
45
|
+
|
|
46
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const { spawn } = require("child_process")
|
|
2
|
+
const waitOn = require("wait-on")
|
|
3
|
+
const getPort = require("get-port")
|
|
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()
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const { app, BrowserWindow } = require("electron")
|
|
2
|
+
const path = require("path")
|
|
3
|
+
|
|
4
|
+
const installExtension = require("electron-devtools-installer")
|
|
5
|
+
const { VUEJS_DEVTOOLS } = require("electron-devtools-installer")
|
|
6
|
+
|
|
7
|
+
const enableHotReload = require("./hot-reload")
|
|
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({
|
|
17
|
+
|
|
18
|
+
width: 1200,
|
|
19
|
+
height: 800,
|
|
20
|
+
|
|
21
|
+
webPreferences: {
|
|
22
|
+
preload: path.join(__dirname, "preload.js"),
|
|
23
|
+
contextIsolation: true
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
if (isDev) {
|
|
29
|
+
|
|
30
|
+
win.loadURL(`http://localhost:${port}`)
|
|
31
|
+
|
|
32
|
+
win.webContents.openDevTools()
|
|
33
|
+
|
|
34
|
+
enableHotReload(win)
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
await installExtension(VUEJS_DEVTOOLS)
|
|
38
|
+
} catch { }
|
|
39
|
+
|
|
40
|
+
} else {
|
|
41
|
+
|
|
42
|
+
win.loadFile(
|
|
43
|
+
path.join(__dirname, "../dist/index.html")
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
app.whenReady().then(createWindow)
|
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vue-cli-plugin-electron-haunv",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"type": "commonjs",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"chokidar": "latest",
|
|
15
|
+
"concurrently": "latest",
|
|
16
|
+
"electron": "latest",
|
|
17
|
+
"electron-builder": "latest",
|
|
18
|
+
"electron-devtools-installer": "latest",
|
|
19
|
+
"get-port": "latest",
|
|
20
|
+
"tree-kill": "latest",
|
|
21
|
+
"wait-on": "latest"
|
|
22
|
+
}
|
|
23
|
+
}
|