Skip to content

Commit 4bb4a93

Browse files
committed
Modify electron-quick-start to use es6 and debug it in VSCode
1 parent 22d85fe commit 4bb4a93

8 files changed

Lines changed: 70 additions & 8 deletions

File tree

electron-quick-start-es6/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015"]
3+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Debug Main Process",
6+
"type": "node",
7+
"request": "launch",
8+
"cwd": "${workspaceRoot}",
9+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
10+
"program": "${workspaceRoot}/main.js"
11+
},
12+
{
13+
"name": "Debug Renderer Process",
14+
"type": "chrome",
15+
"request": "launch",
16+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
17+
"runtimeArgs": [
18+
"http://localhost:4000",
19+
"--remote-debugging-port=9222"
20+
],
21+
"sourceMaps": true,
22+
"webRoot": "${workspaceRoot}"
23+
}
24+
]
25+
}

electron-quick-start-es6/helper.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function sayHello(target) {
2+
console.log(`hello ${target}!`)
3+
}

electron-quick-start-es6/index.html

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,5 @@ <h1>Hello World!</h1>
1212
and Electron <script>document.write(process.versions.electron)</script>.
1313
</body>
1414

15-
<script>
16-
// You can also require other files to run in this process
17-
require('./renderer.js')
18-
</script>
15+
<script src="/dev-dist/renderer.js"></script>
1916
</html>

electron-quick-start-es6/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ function createWindow () {
1313
mainWindow = new BrowserWindow({width: 800, height: 600})
1414

1515
// and load the index.html of the app.
16-
mainWindow.loadURL(`file://${__dirname}/index.html`)
16+
mainWindow.loadURL('http://localhost:4000')
1717

1818
// Open the DevTools.
19-
mainWindow.webContents.openDevTools()
19+
// mainWindow.webContents.openDevTools()
2020

2121
// Emitted when the window is closed.
2222
mainWindow.on('closed', function () {

electron-quick-start-es6/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "A minimal Electron application",
55
"main": "main.js",
66
"scripts": {
7-
"start": "electron ."
7+
"start": "electron .",
8+
"dev": "webpack-dev-server --no-info --quiet --port 4000 --config webpack.config.js"
89
},
910
"repository": {
1011
"type": "git",
@@ -23,6 +24,11 @@
2324
},
2425
"homepage": "https://github.com/electron/electron-quick-start#readme",
2526
"devDependencies": {
26-
"electron": "^1.3.4"
27+
"babel-core": "^6.14.0",
28+
"babel-loader": "^6.2.5",
29+
"babel-preset-es2015": "^6.14.0",
30+
"electron": "^1.3.5",
31+
"webpack": "^1.13.2",
32+
"webpack-dev-server": "^1.16.1"
2733
}
2834
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
// This file is required by the index.html file and will
22
// be executed in the renderer process for that window.
33
// All of the Node.js APIs are available in this process.
4+
5+
import { sayHello } from './helper.js';
6+
7+
sayHello('world')
8+
9+
document.body.addEventListener('click', () => {
10+
sayHello('vscode')
11+
})
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const webpack = require('webpack')
2+
3+
module.exports = {
4+
entry: './renderer.js',
5+
output: {
6+
path: './dist',
7+
publicPath: '/dev-dist',
8+
filename: 'renderer.js'
9+
},
10+
module: {
11+
loaders: [
12+
{
13+
test: /\.js$/,
14+
loader: 'babel',
15+
exclude: /node_modules/
16+
}
17+
]
18+
},
19+
devtool: 'eval-source-map'
20+
}

0 commit comments

Comments
 (0)