lbry-desktop/electron/devServer.js

69 lines
2 KiB
JavaScript
Raw Normal View History

/* 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
);
2019-11-11 16:22:57 +01:00
let [mainConfig, renderConfig] = require('../webpack.electron.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' },
},
});
const mainCompiler = webpack(mainConfig);
const mainInstance = middleware(mainCompiler, {
logLevel: 'warn',
writeToDisk: filename => {
// console.log(`Writing '${filename}'.`);
return true;
},
});
const renderCompiler = webpack(renderConfig);
const renderInstance = middleware(renderCompiler, {
logLevel: 'warn',
publicPath: '/',
});
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
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());
});
process.on('SIGINT', function() {
console.log('Killing threads...');
child.kill('SIGINT');
process.exit();
});
2019-03-13 07:52:14 +01:00
});
/* eslint-enable no-console */