openethereum/js/webpack/dev.server.js

81 lines
2.4 KiB
JavaScript
Raw Normal View History

2016-11-25 13:14:30 +01:00
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// 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');
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-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 () {
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, {
noInfo: false,
quiet: true,
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
}
}));
app.use(express.static(webpackConfig.output.path));
// Add the dev proxies in the express App
Shared.addProxies(app);
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
});