Watch main.js sources

This commit is contained in:
Yuya Ochiai 2017-03-05 00:58:26 +09:00
parent 6f4010edf2
commit 83b84f9fbd
2 changed files with 36 additions and 1 deletions

View file

@ -23,7 +23,8 @@
"build:main": "cross-env NODE_ENV=production webpack --bail --config webpack.config.main.js",
"build:renderer": "cross-env NODE_ENV=production webpack --bail --config webpack.config.renderer.js",
"start": "electron src",
"watch": "run-s watch:*",
"watch": "run-p watch:*",
"watch:main": "node scripts/watch_main_and_preload.js",
"watch:renderer": "webpack-dev-server --config webpack.config.renderer.js",
"serve": "gulp watch",
"test": "npm-run-all build test:* lint:*",

View file

@ -0,0 +1,34 @@
const webpack = require('webpack');
const mainConfig = require('../webpack.config.main.js');
const rendererConfig = require('../webpack.config.renderer.js');
const electron = require('electron-connect').server.create({path: 'src'});
let started = false;
const mainCompiler = webpack(mainConfig);
mainCompiler.watch({}, (err, stats) => {
process.stdout.write(stats.toString({colors: true}));
process.stdout.write('\n');
if (!stats.hasErrors()) {
if (started) {
electron.restart();
} else {
electron.start();
started = true;
}
}
});
for (const key in rendererConfig.entry) {
if (!key.startsWith('webview/')) {
if ({}.hasOwnProperty.call(rendererConfig.entry, key)) {
delete rendererConfig.entry[key];
}
}
}
const preloadCompiler = webpack(rendererConfig);
preloadCompiler.watch({}, (err) => {
if (err) {
console.log(err);
}
});