2016-12-11 19:30:54 +01:00
|
|
|
// Copyright 2015, 2016 Parity Technologies (UK) Ltd.
|
2016-11-25 13:14:30 +01:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
const webpack = require('webpack');
|
2016-12-15 00:07:49 +01:00
|
|
|
const WebpackStats = require('webpack/lib/Stats');
|
2016-11-25 13:14:30 +01:00
|
|
|
const webpackDevMiddleware = require('webpack-dev-middleware');
|
|
|
|
const webpackHotMiddleware = require('webpack-hot-middleware');
|
|
|
|
|
|
|
|
const http = require('http');
|
|
|
|
const express = require('express');
|
2016-11-25 19:32:58 +01:00
|
|
|
const ProgressBar = require('progress');
|
2016-12-21 15:12:40 +01:00
|
|
|
const proxy = require('http-proxy-middleware');
|
2016-11-25 13:14:30 +01:00
|
|
|
|
2016-11-28 16:06:27 +01:00
|
|
|
const webpackConfig = require('./app');
|
2016-11-25 13:14:30 +01:00
|
|
|
const Shared = require('./shared');
|
|
|
|
|
2016-11-25 19:32:58 +01:00
|
|
|
let progressBar = { update: () => {} };
|
2016-11-25 13:14:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add webpack hot middleware to each entry in the config
|
|
|
|
* and HMR to the plugins
|
|
|
|
*/
|
|
|
|
(function updateWebpackConfig () {
|
2016-12-21 15:12:40 +01:00
|
|
|
webpackConfig.performance = { hints: false };
|
|
|
|
|
2016-11-25 13:14:30 +01:00
|
|
|
Object.keys(webpackConfig.entry).forEach((key) => {
|
|
|
|
const entry = webpackConfig.entry[key];
|
|
|
|
|
2016-11-28 12:37:13 +01:00
|
|
|
webpackConfig.entry[key] = [].concat(
|
|
|
|
'react-hot-loader/patch',
|
2016-11-28 13:01:17 +01:00
|
|
|
'webpack-hot-middleware/client?reload=true',
|
2016-11-28 12:37:13 +01:00
|
|
|
entry
|
|
|
|
);
|
2016-11-25 13:14:30 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
webpackConfig.plugins.push(new webpack.HotModuleReplacementPlugin());
|
2016-11-28 12:37:13 +01:00
|
|
|
webpackConfig.plugins.push(new webpack.NamedModulesPlugin());
|
2016-11-25 13:14:30 +01:00
|
|
|
webpackConfig.plugins.push(new webpack.NoErrorsPlugin());
|
2016-11-28 12:37:13 +01:00
|
|
|
|
2016-11-25 19:32:58 +01:00
|
|
|
webpackConfig.plugins.push(new webpack.ProgressPlugin(
|
|
|
|
(percentage) => progressBar.update(percentage)
|
|
|
|
));
|
2016-11-25 13:14:30 +01:00
|
|
|
})();
|
|
|
|
|
|
|
|
const app = express();
|
|
|
|
const compiler = webpack(webpackConfig);
|
|
|
|
|
2016-11-28 12:37:13 +01:00
|
|
|
app.use(webpackHotMiddleware(compiler, {
|
|
|
|
log: console.log
|
|
|
|
}));
|
|
|
|
|
2016-11-25 13:14:30 +01:00
|
|
|
app.use(webpackDevMiddleware(compiler, {
|
2016-12-15 00:07:49 +01:00
|
|
|
noInfo: true,
|
|
|
|
quiet: false,
|
2016-11-25 19:32:58 +01:00
|
|
|
progress: true,
|
2016-11-25 13:14:30 +01:00
|
|
|
publicPath: webpackConfig.output.publicPath,
|
|
|
|
stats: {
|
|
|
|
colors: true
|
2016-12-15 00:07:49 +01:00
|
|
|
},
|
|
|
|
reporter: function (data) {
|
|
|
|
// @see https://github.com/webpack/webpack/blob/324d309107f00cfc38ec727521563d309339b2ec/lib/Stats.js#L790
|
|
|
|
// Accepted values: none, errors-only, minimal, normal, verbose
|
|
|
|
const options = WebpackStats.presetToOptions('minimal');
|
|
|
|
options.timings = true;
|
|
|
|
|
|
|
|
const output = data.stats.toString(options);
|
|
|
|
|
|
|
|
process.stdout.write('\n');
|
|
|
|
process.stdout.write(output);
|
|
|
|
process.stdout.write('\n\n');
|
2016-11-25 13:14:30 +01:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
2016-12-21 15:12:40 +01:00
|
|
|
var wsProxy = proxy('ws://127.0.0.1:8180', { changeOrigin: true });
|
2016-11-25 13:14:30 +01:00
|
|
|
|
|
|
|
// Add the dev proxies in the express App
|
|
|
|
Shared.addProxies(app);
|
|
|
|
|
2016-12-21 15:12:40 +01:00
|
|
|
app.use(express.static(webpackConfig.output.path));
|
|
|
|
app.use(wsProxy);
|
|
|
|
|
2016-11-25 13:14:30 +01:00
|
|
|
const server = http.createServer(app);
|
|
|
|
server.listen(process.env.PORT || 3000, function () {
|
|
|
|
console.log('Listening on port', server.address().port);
|
2016-11-25 19:32:58 +01:00
|
|
|
progressBar = new ProgressBar('[:bar] :percent :etas', { total: 50 });
|
2016-11-25 13:14:30 +01:00
|
|
|
});
|
2016-12-21 15:12:40 +01:00
|
|
|
|
|
|
|
server.on('upgrade', wsProxy.upgrade);
|