live reload on disk

This commit is contained in:
Daniel Prado
2017-04-12 13:57:43 -03:00
committed by Maxime GRIS
parent a172df94d9
commit 7bb2f8b20a
2 changed files with 16 additions and 12 deletions

25
main.js
View File

@@ -5,7 +5,13 @@ const {app} = electron;
// Module to create native browser window.
const {BrowserWindow} = electron;
let win;
let win, serve;
const args = process.argv.slice(1);
serve = args.some(val => val === "--serve");
if (serve) {
require('electron-reload')(__dirname + '/dist');
}
function createWindow() {
@@ -20,20 +26,17 @@ function createWindow() {
height: size.height
});
let url = 'file://' + __dirname + '/index.html';
let Args = process.argv.slice(1);
Args.forEach(function (val) {
if (val === "--serve") {
url = 'http://localhost:4200'
}
});
let url = serve ?
'file://' + __dirname + '/dist/index.html':
'file://' + __dirname + '/index.html';
// and load the index.html of the app.
win.loadURL(url);
// Open the DevTools.
win.webContents.openDevTools();
if (serve) {
win.webContents.openDevTools();
}
// Emitted when the window is closed.
win.on('closed', () => {
@@ -64,4 +67,4 @@ app.on('activate', () => {
if (win === null) {
createWindow();
}
});
});