Skip to content

Commit bbc9999

Browse files
rigor789michalsnik
authored andcommitted
Create a minimal electron shell for vue-devtools.
1 parent 130e43e commit bbc9999

File tree

8 files changed

+154
-0
lines changed

8 files changed

+154
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"dev": "cd shells/dev && webpack-dev-server --inline --hot --no-info",
88
"dev:chrome": "cd shells/chrome && webpack --watch --hide-modules",
9+
"dev:electron": "cd shells/electron && webpack --watch --hide-modules",
910
"dev:safari": "cd shells/safari && webpack --watch --hide-modules",
1011
"lint": "eslint src --ext=js,vue && eslint shells/chrome/src && eslint shells/dev/src && eslint shells/safari/src",
1112
"build": "cd shells/chrome && cross-env NODE_ENV=production webpack --progress --hide-modules",

shells/electron/app.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Vue Developer Tools</title>
6+
<style>
7+
body {
8+
display: flex;
9+
flex-direction: column;
10+
position: absolute;
11+
top: 0;
12+
left: 0;
13+
right: 0;
14+
bottom: 0;
15+
margin: 0;
16+
padding: 0;
17+
}
18+
</style>
19+
</head>
20+
<body>
21+
<div id="app"></div>
22+
<script src="build/devtools.js"></script>
23+
</body>
24+
</html>

shells/electron/app.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const { app, BrowserWindow } = require('electron')
2+
3+
let mainWindow = null
4+
5+
app.on('window-all-closed', () => app.quit())
6+
app.on('ready', () => {
7+
mainWindow = new BrowserWindow({ width: 800, height: 600 })
8+
9+
mainWindow.loadURL('file://' + __dirname + '/app.html')
10+
11+
mainWindow.on('closed', () => mainWindow = null)
12+
})

shells/electron/bin.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const electron = require('electron')
2+
const spawn = require('cross-spawn')
3+
4+
const result = spawn.sync(
5+
electron,
6+
[require.resolve('./app')],
7+
)
8+
9+
process.exit(result.status)

shells/electron/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "vue-devtools",
3+
"version": "0.0.1",
4+
"description": "StandAlone vue-devtools",
5+
"bin": {
6+
"vue-devtools": "./bin.js"
7+
},
8+
"scripts": {
9+
"start": "node bin.js"
10+
},
11+
"author": "",
12+
"license": "MIT",
13+
"dependencies": {
14+
"cross-spawn": "^5.1.0",
15+
"electron": "^1.8.1"
16+
}
17+
}

shells/electron/src/backend.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { initBackend } from 'src/backend'
2+
import Bridge from 'src/bridge'
3+
4+
const bridge = new Bridge({
5+
listen (fn) {
6+
window.addEventListener('message', evt => fn(evt.data))
7+
},
8+
send (data) {
9+
console.log('backend -> devtools', data)
10+
window.parent.postMessage(data, '*')
11+
}
12+
})
13+
14+
initBackend(bridge)

shells/electron/src/devtools.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { initDevTools } from 'src/devtools'
2+
import Bridge from 'src/bridge'
3+
4+
initDevTools({
5+
connect(callback) {
6+
console.log('connect has been called')
7+
8+
const wall = {
9+
listen(fn) {
10+
console.log('wall.listen has been called')
11+
},
12+
send(data) {
13+
console.log('wall.send has been called', data)
14+
}
15+
}
16+
const bridge = new Bridge(wall)
17+
18+
callback(bridge)
19+
},
20+
onReload(fn) {
21+
console.log('onReload has been called')
22+
}
23+
})

shells/electron/webpack.config.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
var path = require('path')
2+
var webpack = require('webpack')
3+
var alias = require('../alias')
4+
var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
5+
6+
var bubleOptions = {
7+
target: { chrome: 52, firefox: 48 },
8+
objectAssign: 'Object.assign'
9+
}
10+
11+
module.exports = {
12+
entry: {
13+
devtools: './src/devtools.js',
14+
backend: './src/backend.js',
15+
},
16+
output: {
17+
path: __dirname + '/build',
18+
publicPath: '/build/',
19+
filename: '[name].js',
20+
},
21+
resolve: {
22+
alias
23+
},
24+
module: {
25+
rules: [
26+
{
27+
test: /\.js$/,
28+
loader: 'buble-loader',
29+
exclude: /node_modules|vue\/dist|vuex\/dist/,
30+
options: bubleOptions
31+
},
32+
{
33+
test: /\.vue$/,
34+
loader: 'vue-loader',
35+
options: {
36+
preserveWhitespace: false,
37+
buble: bubleOptions
38+
}
39+
},
40+
{
41+
test: /\.(png|woff2)$/,
42+
loader: 'url-loader?limit=0'
43+
}
44+
]
45+
},
46+
performance: {
47+
hints: false
48+
},
49+
devtool: '#cheap-module-source-map',
50+
devServer: {
51+
quiet: true
52+
},
53+
plugins: process.env.VUE_DEVTOOL_TEST ? [] :[new FriendlyErrorsPlugin()]
54+
}

0 commit comments

Comments
 (0)