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

21
main.js
View File

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

View File

@@ -17,7 +17,7 @@
"private": true, "private": true,
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"start": "webpack-dev-server --port=4200", "start": "webpack --watch",
"test": "karma start ./karma.conf.js", "test": "karma start ./karma.conf.js",
"lint": "ng lint", "lint": "ng lint",
"e2e": "protractor ./protractor.conf.js", "e2e": "protractor ./protractor.conf.js",
@@ -57,6 +57,7 @@
"electron": "~1.6.2", "electron": "~1.6.2",
"electron-packager": "~8.6.0", "electron-packager": "~8.6.0",
"electron-prebuilt": "~1.4.13", "electron-prebuilt": "~1.4.13",
"electron-reload": "^1.1.0",
"exports-loader": "~0.6.3", "exports-loader": "~0.6.3",
"file-loader": "~0.10.0", "file-loader": "~0.10.0",
"istanbul-instrumenter-loader": "~2.0.0", "istanbul-instrumenter-loader": "~2.0.0",