2019-08-23 17:54:08 +02:00
|
|
|
/* eslint-disable no-console */
|
2019-11-11 16:22:57 +01:00
|
|
|
const { WEBPACK_ELECTRON_PORT } = require('../config');
|
2019-03-13 07:52:14 +01:00
|
|
|
const chalk = require('chalk');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
const merge = require('webpack-merge');
|
|
|
|
const middleware = require('webpack-dev-middleware');
|
|
|
|
const express = require('express');
|
|
|
|
const app = express();
|
|
|
|
|
|
|
|
console.log(
|
2019-05-07 23:38:29 +02:00
|
|
|
chalk.magenta(`Compiling ${chalk.underline('main')} and ${chalk.underline('render')}, this will take a while.`)
|
2019-03-13 07:52:14 +01:00
|
|
|
);
|
|
|
|
|
2020-11-12 22:12:25 +01:00
|
|
|
let [mainConfig, renderConfig] = require('../webpack.electron-main.config.js');
|
2019-03-13 07:52:14 +01:00
|
|
|
|
|
|
|
renderConfig = merge(renderConfig, {
|
|
|
|
entry: { ui: ['webpack-hot-middleware/client'] },
|
|
|
|
plugins: [new webpack.HotModuleReplacementPlugin()],
|
|
|
|
resolve: {
|
|
|
|
alias: { 'react-dom': '@hot-loader/react-dom' },
|
2019-11-21 17:38:41 +01:00
|
|
|
symlinks: false,
|
2019-03-13 07:52:14 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const mainCompiler = webpack(mainConfig);
|
2020-11-12 22:12:25 +01:00
|
|
|
const mainInstance = middleware(mainCompiler, { writeToDisk: true });
|
2019-03-13 07:52:14 +01:00
|
|
|
const renderCompiler = webpack(renderConfig);
|
|
|
|
const renderInstance = middleware(renderCompiler, {
|
|
|
|
publicPath: '/',
|
2020-11-12 22:12:25 +01:00
|
|
|
writeToDisk: true,
|
2019-03-13 07:52:14 +01:00
|
|
|
});
|
2020-11-12 22:12:25 +01:00
|
|
|
|
2019-03-13 07:52:14 +01:00
|
|
|
app.use(require('webpack-hot-middleware')(renderCompiler));
|
|
|
|
app.use(renderInstance);
|
2019-03-15 20:37:51 +01:00
|
|
|
app.use(express.static('dist/electron/static'));
|
2019-03-13 07:52:14 +01:00
|
|
|
|
2019-08-23 17:54:08 +02:00
|
|
|
app.listen(WEBPACK_ELECTRON_PORT, () => {
|
|
|
|
console.log(chalk.yellow.bold(`Renderer listening on port ${WEBPACK_ELECTRON_PORT} (still compiling)`));
|
2019-03-13 07:52:14 +01:00
|
|
|
});
|
|
|
|
|
2019-05-07 23:38:29 +02:00
|
|
|
mainInstance.waitUntilValid(() => console.log(chalk.green(`${chalk.underline('main')} compilation complete.`)));
|
|
|
|
renderInstance.waitUntilValid(() => console.log(chalk.green(`${chalk.underline('render')} compilation complete.`)));
|
2019-03-13 07:52:14 +01:00
|
|
|
|
|
|
|
mainInstance.waitUntilValid(() => {
|
|
|
|
console.log(chalk.yellow('Spawning electron...'));
|
|
|
|
|
|
|
|
const electron = require('electron');
|
|
|
|
const proc = require('child_process');
|
|
|
|
|
2019-03-15 20:37:51 +01:00
|
|
|
const child = proc.spawn(electron, ['./dist/electron/webpack/main.js']);
|
2019-03-15 02:54:17 +01:00
|
|
|
|
2019-03-25 07:18:22 +01:00
|
|
|
child.stdout.on('data', data => {
|
2019-03-15 02:54:17 +01:00
|
|
|
console.log(data.toString());
|
|
|
|
});
|
2019-03-16 04:55:01 +01:00
|
|
|
|
|
|
|
process.on('SIGINT', function() {
|
|
|
|
console.log('Killing threads...');
|
|
|
|
|
|
|
|
child.kill('SIGINT');
|
|
|
|
process.exit();
|
|
|
|
});
|
2019-03-13 07:52:14 +01:00
|
|
|
});
|
2019-08-23 17:54:08 +02:00
|
|
|
/* eslint-enable no-console */
|