Skip to content

Commit 7539d76

Browse files
author
fbarl
committed
Switched to using webpack-dev-middleware instead of webpack-dev-server directly
1 parent 3083871 commit 7539d76

File tree

9 files changed

+49
-86
lines changed

9 files changed

+49
-86
lines changed

client/.babelrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"presets": ["es2015", "react"],
3-
"plugins": ["react-hot-loader/babel"]
2+
"presets": ["es2015", "react"]
43
}

client/app/scripts/contrast-main.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'babel-polyfill';
66
import React from 'react';
77
import ReactDOM from 'react-dom';
88
import { Provider } from 'react-redux';
9-
import { AppContainer } from 'react-hot-loader';
109
import configureStore from './stores/configureStore';
1110

1211
const store = configureStore();
@@ -15,9 +14,7 @@ function renderApp() {
1514
const App = require('./components/app').default;
1615
ReactDOM.render((
1716
<Provider store={store}>
18-
<AppContainer>
19-
<App />
20-
</AppContainer>
17+
<App />
2118
</Provider>
2219
), document.getElementById('app'));
2320
}

client/app/scripts/main.dev.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'babel-polyfill';
66
import React from 'react';
77
import ReactDOM from 'react-dom';
88
import { Provider } from 'react-redux';
9-
import { AppContainer } from 'react-hot-loader';
109
import configureStore from './stores/configureStore.dev';
1110

1211
import DevTools from './components/dev-tools';
@@ -20,9 +19,7 @@ function renderApp() {
2019
const App = require('./components/app').default;
2120
ReactDOM.render((
2221
<Provider store={store}>
23-
<AppContainer>
24-
<App />
25-
</AppContainer>
22+
<App />
2623
<DevTools />
2724
</Provider>
2825
), document.getElementById('app'));

client/app/scripts/main.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'babel-polyfill';
66
import React from 'react';
77
import ReactDOM from 'react-dom';
88
import { Provider } from 'react-redux';
9-
import { AppContainer } from 'react-hot-loader';
109
import configureStore from './stores/configureStore';
1110

1211
const store = configureStore();
@@ -15,9 +14,7 @@ function renderApp() {
1514
const App = require('./components/app').default;
1615
ReactDOM.render((
1716
<Provider store={store}>
18-
<AppContainer>
19-
<App />
20-
</AppContainer>
17+
<App />
2118
</Provider>
2219
), document.getElementById('app'));
2320
}

client/app/scripts/terminal-main.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,17 @@ import 'babel-polyfill';
55
import React from 'react';
66
import ReactDOM from 'react-dom';
77
import { Provider } from 'react-redux';
8-
import { AppContainer } from 'react-hot-loader';
98
import configureStore from './stores/configureStore';
109

1110
const store = configureStore();
1211

1312
function renderApp() {
1413
const TerminalApp = require('./components/terminal-app').default;
15-
ReactDOM.render(
14+
ReactDOM.render((
1615
<Provider store={store}>
17-
<AppContainer>
18-
<TerminalApp />
19-
</AppContainer>
20-
</Provider>,
21-
document.getElementById('app')
22-
);
16+
<TerminalApp />
17+
</Provider>
18+
), document.getElementById('app'));
2319
}
2420

2521
renderApp();

client/app/styles/contrast.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434

3535
/* specific elements */
3636
@body-background-color: #FFF;
37-
@label-background-color: #FFF;
37+
@label-background-color: #FFF;

client/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474
"express": "~4.14.0",
7575
"http-proxy": "^1.15.2",
7676
"perfjankie": "^2.1.0",
77-
"react-hot-loader": "3.0.0-beta.6",
78-
"webpack-dev-server": "~1.16.2"
77+
"webpack-dev-middleware": "^1.8.4",
78+
"webpack-hot-middleware": "^2.13.2"
7979
},
8080
"scripts": {
8181
"build": "webpack --config webpack.production.config.js",

client/server.js

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,11 @@ var WEBPACK_SERVER_HOST = process.env.WEBPACK_SERVER_HOST || 'localhost';
1111

1212
/************************************************************
1313
*
14-
* Express routes for:
15-
* - app.js
16-
* - app-terminal.js
17-
* - index.html
18-
*
19-
* Proxy requests to:
20-
* - /api -> :4040/api
14+
* Proxy requests to:
15+
* - /api -> :4040/api
2116
*
2217
************************************************************/
2318

24-
// Proxy to backend
25-
2619
var backendProxy = httpProxy.createProxy({
2720
ws: true,
2821
target: 'http://' + BACKEND_HOST + ':4040'
@@ -32,49 +25,45 @@ backendProxy.on('error', function(err) {
3225
});
3326
app.all('/api*', backendProxy.web.bind(backendProxy));
3427

35-
// Serve application file depending on environment
28+
/************************************************************
29+
*
30+
* Production env serves precompiled content from build/
31+
*
32+
************************************************************/
3633

3734
if (process.env.NODE_ENV === 'production') {
38-
// serve all precompiled content from build/
3935
app.use(express.static('build'));
40-
} else {
41-
// redirect the JS bundles
42-
app.get(/.*js/, function(req, res) {
43-
res.redirect('//' + WEBPACK_SERVER_HOST + ':4041' + req.originalUrl);
44-
});
45-
// proxy everything else
46-
var staticProxy = httpProxy.createProxy({
47-
target: 'http://' + WEBPACK_SERVER_HOST + ':4041'
48-
});
49-
app.all('*', staticProxy.web.bind(staticProxy));
5036
}
5137

5238
/*************************************************************
5339
*
54-
* Webpack Dev Server
40+
* Webpack Dev Middleware with Hot Reload
5541
*
56-
* See: http://webpack.github.io/docs/webpack-dev-server.html
42+
* See: https://github.com/webpack/webpack-dev-middleware;
43+
* https://github.com/glenjamin/webpack-hot-middleware
5744
*
5845
*************************************************************/
5946

6047
if (process.env.NODE_ENV !== 'production') {
6148
var webpack = require('webpack');
62-
var WebpackDevServer = require('webpack-dev-server');
49+
var webpackMiddleware = require('webpack-dev-middleware');
50+
var webpackHotMiddleware = require('webpack-hot-middleware');
6351
var config = require('./webpack.local.config');
52+
var compiler = webpack(config);
6453

65-
new WebpackDevServer(webpack(config), {
66-
hot: true,
54+
app.use(webpackMiddleware(compiler, {
55+
// required
56+
publicPath: config.output.publicPath,
57+
// options
6758
noInfo: true,
68-
historyApiFallback: true,
59+
watchOptions: {
60+
aggregateTimeout: 500,
61+
poll: true
62+
},
6963
stats: 'errors-only',
70-
// We need the access from the express server for the hot-loader.
71-
// See: https://github.com/gaearon/react-hot-loader/issues/56
72-
headers: { "Access-Control-Allow-Origin": '*' },
73-
}).listen(4041, '0.0.0.0', function (err, result) {
74-
if (err) {
75-
console.log(err);
76-
}
77-
});
64+
}));
65+
66+
app.use(webpackHotMiddleware(compiler));
7867
}
7968

8069

@@ -97,7 +86,7 @@ server.on('upgrade', backendProxy.ws.bind(backendProxy));
9786

9887
/*************************************************************
9988
*
100-
* path proxy server
89+
* Path proxy server
10190
*
10291
*************************************************************/
10392

client/webpack.local.config.js

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,54 @@ const path = require('path');
44
const HtmlWebpackPlugin = require('html-webpack-plugin');
55

66
/**
7-
* This is the Webpack configuration file for local development. It contains
8-
* local-specific configuration such as the React Hot Loader, as well as:
7+
* This is the Webpack configuration file for local development.
8+
* It contains local-specific configuration which includes:
99
*
10-
* - The entry point of the application
11-
* - Where the output file should be
10+
* - Hot reloading configuration
11+
* - The entry points of the application
1212
* - Which loaders to use on what files to properly transpile the source
1313
*
1414
* For more information, see: http://webpack.github.io/docs/configuration.html
1515
*/
1616

17-
// Inject websocket url to dev backend
18-
const WEBPACK_SERVER_HOST = process.env.WEBPACK_SERVER_HOST || 'localhost';
19-
const DEV_SERVER_URL = `webpack-dev-server/client?http://${WEBPACK_SERVER_HOST}:4041`;
20-
2117
module.exports = {
22-
2318
// Efficiently evaluate modules with source maps
2419
devtool: 'source-map',
2520

26-
// Set entry point include necessary files for hot load
21+
// Set entry points with hot loading
2722
entry: {
2823
app: [
29-
'react-hot-loader/patch',
30-
DEV_SERVER_URL,
31-
'webpack/hot/only-dev-server',
3224
'./app/scripts/main',
25+
'webpack-hot-middleware/client'
3326
],
3427
'dev-app': [
35-
'react-hot-loader/patch',
36-
DEV_SERVER_URL,
37-
'webpack/hot/only-dev-server',
3828
'./app/scripts/main.dev',
29+
'webpack-hot-middleware/client'
3930
],
4031
'contrast-app': [
41-
'react-hot-loader/patch',
42-
DEV_SERVER_URL,
43-
'webpack/hot/only-dev-server',
4432
'./app/scripts/contrast-main',
33+
'webpack-hot-middleware/client'
4534
],
4635
'terminal-app': [
47-
'react-hot-loader/patch',
48-
DEV_SERVER_URL,
49-
'webpack/hot/only-dev-server',
5036
'./app/scripts/terminal-main',
37+
'webpack-hot-middleware/client'
5138
],
5239
vendors: ['babel-polyfill', 'classnames', 'd3', 'dagre', 'filesize', 'immutable', 'lodash',
5340
'moment', 'page', 'react', 'react-dom', 'react-motion', 'react-redux', 'redux',
5441
'redux-thunk', 'reqwest', 'xterm']
5542
},
5643

57-
// This will not actually create a app.js file in ./build. It is used
58-
// by the dev server for dynamic hot loading.
44+
// Used by Webpack Dev Middleware
5945
output: {
60-
path: path.join(__dirname, 'build/'),
46+
publicPath: '/',
47+
path: '/',
6148
filename: '[name].js'
6249
},
6350

6451
// Necessary plugins for hot load
6552
plugins: [
6653
new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js'),
54+
new webpack.optimize.OccurrenceOrderPlugin(),
6755
new webpack.HotModuleReplacementPlugin(),
6856
new webpack.NoErrorsPlugin(),
6957
new webpack.IgnorePlugin(/^\.\/locale$/, [/moment$/]),

0 commit comments

Comments
 (0)