Skip to content

Commit 7bb2f8b

Browse files
danielopradomaximegris
authored andcommitted
live reload on disk
1 parent a172df9 commit 7bb2f8b

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

Diff for: main.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ const {app} = electron;
55
// Module to create native browser window.
66
const {BrowserWindow} = electron;
77

8-
let win;
8+
let win, serve;
9+
const args = process.argv.slice(1);
10+
serve = args.some(val => val === "--serve");
11+
12+
if (serve) {
13+
require('electron-reload')(__dirname + '/dist');
14+
}
915

1016
function createWindow() {
1117

@@ -20,20 +26,17 @@ function createWindow() {
2026
height: size.height
2127
});
2228

23-
let url = 'file://' + __dirname + '/index.html';
24-
let Args = process.argv.slice(1);
25-
26-
Args.forEach(function (val) {
27-
if (val === "--serve") {
28-
url = 'http://localhost:4200'
29-
}
30-
});
29+
let url = serve ?
30+
'file://' + __dirname + '/dist/index.html':
31+
'file://' + __dirname + '/index.html';
3132

3233
// and load the index.html of the app.
3334
win.loadURL(url);
3435

3536
// Open the DevTools.
36-
win.webContents.openDevTools();
37+
if (serve) {
38+
win.webContents.openDevTools();
39+
}
3740

3841
// Emitted when the window is closed.
3942
win.on('closed', () => {
@@ -64,4 +67,4 @@ app.on('activate', () => {
6467
if (win === null) {
6568
createWindow();
6669
}
67-
});
70+
});

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"private": true,
1818
"scripts": {
1919
"ng": "ng",
20-
"start": "webpack-dev-server --port=4200",
20+
"start": "webpack --watch",
2121
"test": "karma start ./karma.conf.js",
2222
"lint": "ng lint",
2323
"e2e": "protractor ./protractor.conf.js",
@@ -57,6 +57,7 @@
5757
"electron": "~1.6.2",
5858
"electron-packager": "~8.6.0",
5959
"electron-prebuilt": "~1.4.13",
60+
"electron-reload": "^1.1.0",
6061
"exports-loader": "~0.6.3",
6162
"file-loader": "~0.10.0",
6263
"istanbul-instrumenter-loader": "~2.0.0",

0 commit comments

Comments
 (0)