Skip to content

Commit cc32447

Browse files
committed
init
1 parent 12015cd commit cc32447

File tree

11 files changed

+1407
-45
lines changed

11 files changed

+1407
-45
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ pnpm-debug.log*
2121
*.njsproj
2222
*.sln
2323
*.sw?
24+
25+
#Electron-builder output
26+
/dist_electron

README.md

+68-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,82 @@
11
# travis-electron-vue-demo
22

3-
## Project setup
3+
通过vue-cli及vue-cli-plugin-electron-builder插件创建electron-vue项目
4+
5+
6+
# 安装
7+
8+
## vue-cli
9+
10+
```
11+
# 卸载老版本vue-cli
12+
yarn global remove vue-cli
13+
yarn global add @vue/cli
14+
```
15+
## yarn
16+
```
17+
# 设置yarn源为淘宝镜像
18+
yarn config set registry https://registry.npm.taobao.org
19+
20+
# 设置代理
21+
yarn config set proxy http://username:password@server:port
22+
yarn config set https-proxy http://username:password@server:port
23+
24+
# 删除代理
25+
yarn config delete proxy
26+
yarn config delete https-proxy
27+
```
28+
29+
30+
# 我的版本
31+
- node:10.15.3
32+
- vue-cli:4.5.7
33+
- yarn:1.21.1
34+
35+
# 初始化
36+
37+
## 创建项目
38+
439
```
5-
yarn install
40+
vue create <project_name>
641
```
742

8-
### Compiles and hot-reloads for development
43+
## 集成electron
44+
945
```
10-
yarn serve
46+
vue add vue-cli-plugin-electron-builder
1147
```
1248

13-
### Compiles and minifies for production
49+
## 更新electron
50+
1451
```
15-
yarn build
52+
yarn add electron@<version> -D
1653
```
1754

18-
### Lints and fixes files
55+
# FAQ
56+
57+
## electorn:serve执行时出现超时告警问题
58+
1959
```
20-
yarn lint
60+
INFO Launching Electron...
61+
Failed to fetch extension, trying 4 more times
62+
Failed to fetch extension, trying 3 more times
63+
Failed to fetch extension, trying 2 more times
64+
Failed to fetch extension, trying 1 more times
65+
Failed to fetch extension, trying 0 more times
66+
Vue Devtools failed to install: Error: net::ERR_CONNECTION_TIMED_OUT
2167
```
68+
造成上述告警原因是,在启动时会对vue.js devtools进行检查,如果不存在会进行联网下载,但由于google被墙,所以必然会下载失败,便会显示这样的告警了。
69+
70+
> 解决方案:
2271
23-
### Customize configuration
24-
See [Configuration Reference](https://cli.vuejs.org/config/).
72+
在background.js中,禁用掉下载插件的逻辑,便可以解决这一问题
73+
74+
```
75+
// Install Vue Devtools
76+
try {
77+
// await installExtension(VUEJS_DEVTOOLS)
78+
console.log('Skip download Vue Devtools.')
79+
} catch (e) {
80+
console.error('Vue Devtools failed to install:', e.toString())
81+
}
82+
```

docker-build.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#! /bin/bash
2+
docker run --rm -ti \
3+
--env-file <(env | grep -iE 'DEBUG|NODE_|ELECTRON_|YARN_|NPM_|CI|CIRCLE|TRAVIS_TAG|TRAVIS|TRAVIS_REPO_|TRAVIS_BUILD_|TRAVIS_BRANCH|TRAVIS_PULL_REQUEST_|APPVEYOR_|CSC_|GH_|GITHUB_|BT_|AWS_|STRIP|BUILD_') \
4+
--env ELECTRON_CACHE="/root/.cache/electron" \
5+
--env ELECTRON_BUILDER_CACHE="/root/.cache/electron-builder" \
6+
-v ${PWD}:/project \
7+
-v ~/.cache/electron:/root/.cache/electron \
8+
-v ~/.cache/electron-builder:/root/.cache/electron-builder \
9+
electronuserland/builder:wine

icon/darwin/icon.icns

473 KB
Binary file not shown.

icon/icon.png

19.1 KB
Loading

icon/linux/icon.png

19.1 KB
Loading

icon/win32/icon.ico

43.8 KB
Binary file not shown.

package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
{
22
"name": "travis-electron-vue-demo",
3-
"version": "0.1.0",
3+
"author": "wuyue <[email protected]>",
4+
"description": "An electron-vue project",
5+
"version": "1.0.0",
46
"private": true,
57
"scripts": {
68
"serve": "vue-cli-service serve",
79
"build": "vue-cli-service build",
8-
"lint": "vue-cli-service lint"
10+
"lint": "vue-cli-service lint",
11+
"electron:build": "vue-cli-service electron:build",
12+
"electron:serve": "vue-cli-service electron:serve",
13+
"postinstall": "electron-builder install-app-deps",
14+
"postuninstall": "electron-builder install-app-deps"
915
},
16+
"main": "background.js",
1017
"dependencies": {
1118
"core-js": "^3.6.5",
1219
"vue": "^2.6.11",
@@ -21,6 +28,8 @@
2128
"@vue/cli-service": "~4.5.0",
2229
"@vue/eslint-config-standard": "^5.1.2",
2330
"babel-eslint": "^10.1.0",
31+
"electron": "^9.0.0",
32+
"electron-devtools-installer": "^3.1.0",
2433
"eslint": "^6.7.2",
2534
"eslint-plugin-import": "^2.20.2",
2635
"eslint-plugin-node": "^11.1.0",
@@ -30,6 +39,7 @@
3039
"less": "^3.0.4",
3140
"less-loader": "^5.0.0",
3241
"lint-staged": "^9.5.0",
42+
"vue-cli-plugin-electron-builder": "~2.0.0-rc.4",
3343
"vue-template-compiler": "^2.6.11"
3444
},
3545
"gitHooks": {

src/background.js

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
'use strict'
2+
3+
import { app, protocol, BrowserWindow } from 'electron'
4+
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
5+
// import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer'
6+
const isDevelopment = process.env.NODE_ENV !== 'production'
7+
8+
// Keep a global reference of the window object, if you don't, the window will
9+
// be closed automatically when the JavaScript object is garbage collected.
10+
let win
11+
12+
// Scheme must be registered before the app is ready
13+
protocol.registerSchemesAsPrivileged([
14+
{ scheme: 'app', privileges: { secure: true, standard: true } }
15+
])
16+
17+
function createWindow () {
18+
// Create the browser window.
19+
win = new BrowserWindow({
20+
width: 800,
21+
height: 600,
22+
webPreferences: {
23+
// Use pluginOptions.nodeIntegration, leave this alone
24+
// See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
25+
nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION
26+
}
27+
})
28+
29+
if (process.env.WEBPACK_DEV_SERVER_URL) {
30+
// Load the url of the dev server if in development mode
31+
win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
32+
if (!process.env.IS_TEST) win.webContents.openDevTools()
33+
} else {
34+
createProtocol('app')
35+
// Load the index.html when not in development
36+
win.loadURL('app://./index.html')
37+
}
38+
39+
win.on('closed', () => {
40+
win = null
41+
})
42+
}
43+
44+
// Quit when all windows are closed.
45+
app.on('window-all-closed', () => {
46+
// On macOS it is common for applications and their menu bar
47+
// to stay active until the user quits explicitly with Cmd + Q
48+
if (process.platform !== 'darwin') {
49+
app.quit()
50+
}
51+
})
52+
53+
app.on('activate', () => {
54+
// On macOS it's common to re-create a window in the app when the
55+
// dock icon is clicked and there are no other windows open.
56+
if (win === null) {
57+
createWindow()
58+
}
59+
})
60+
61+
// This method will be called when Electron has finished
62+
// initialization and is ready to create browser windows.
63+
// Some APIs can only be used after this event occurs.
64+
app.on('ready', async () => {
65+
if (isDevelopment && !process.env.IS_TEST) {
66+
// Install Vue Devtools
67+
try {
68+
// await installExtension(VUEJS_DEVTOOLS)
69+
console.log('Skip download Vue Devtools.')
70+
} catch (e) {
71+
console.error('Vue Devtools failed to install:', e.toString())
72+
}
73+
}
74+
createWindow()
75+
})
76+
77+
// Exit cleanly on request from parent process in development mode.
78+
if (isDevelopment) {
79+
if (process.platform === 'win32') {
80+
process.on('message', (data) => {
81+
if (data === 'graceful-exit') {
82+
app.quit()
83+
}
84+
})
85+
} else {
86+
process.on('SIGTERM', () => {
87+
app.quit()
88+
})
89+
}
90+
}

vue.config.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = {
2+
pluginOptions: {
3+
electronBuilder: {
4+
builderOptions: {
5+
// options placed here will be merged with default configuration and passed to electron-builder
6+
productName: 'travis-electron-vue-demo',
7+
appId: 'com.example.travis-electron-vue-demo',
8+
nsis: {
9+
oneClick: false,
10+
allowToChangeInstallationDirectory: true,
11+
installerIcon: 'icon/win32/icon.ico',
12+
createDesktopShortcut: true,
13+
createStartMenuShortcut: true
14+
},
15+
mac: {
16+
icon: 'icon/darwin/icon.icns',
17+
artifactName: '${name}-setup-${version}.${ext}',
18+
target: 'pkg'
19+
},
20+
win: {
21+
icon: 'icon/win32/icon.ico',
22+
artifactName: '${name}-setup-${version}.${ext}'
23+
},
24+
linux: {
25+
icon: 'icon/linux/icon.png',
26+
artifactName: '${name}-setup-${version}.${ext}'
27+
}
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)