forked from tomcl/issie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.js
71 lines (57 loc) · 1.9 KB
/
start.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const configMain = require('../webpack.config.main');
const configRenderer = require('../webpack.config.renderer');
const { spawn } = require('child_process');
const path = require('path');
const del = require('del');
const { shell } = require('electron');
const compilerMain = webpack(configMain);
const compilerRenderer = webpack(configRenderer);
const buildPath = path.join(__dirname, '../build');
let electronStarted = false;
(async () => {
/**
* Delete build dir
*/
await del([buildPath], { force: true });
/**
* Start renderer dev server
*/
const renderSrvOpts = {
hot: true,
host: "localhost",
port: 9000
};
const server = new WebpackDevServer(renderSrvOpts, compilerRenderer);
await server.start();
console.log(`> Dev server is listening on port ${renderSrvOpts.port}`);
/**
* Start Electron
*/
const startElectron = () => {
var electronPath = path.join(process.cwd(), 'node_modules', '.bin', process.platform === 'win32' ? 'electron.cmd' : 'electron');
electronPath = '\"' + electronPath + '\"';
var buildFile = path.join(buildPath, 'index.js');
buildFile = '\"' + buildFile + '\"';
const electron = spawn(electronPath, [buildFile],{stdio: 'inherit', shell:true});
electron.on('exit', function () {
process.exit(0);
});
}
/**
* Start main
*/
const startMain = (stats) => {
console.log('> Renderer started');
if(!electronStarted){
electronStarted = true;
compilerMain.run((err, stats) => {
console.log('> Starting Electron (main)');
});
compilerMain.hooks.afterEmit.tap('on-main-build', startElectron);
}
return;
}
server.compiler.hooks.afterEmit.tap('on-renderer-start', startMain);
})();