Skip to content

Commit dfd0950

Browse files
committed
Switch universal example to webpack-dev-middleware.
1 parent 5c8f9ea commit dfd0950

File tree

5 files changed

+38
-50
lines changed

5 files changed

+38
-50
lines changed

examples/universal/.babelrc

Lines changed: 0 additions & 17 deletions
This file was deleted.

examples/universal/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"start": "npm run server & npm run client",
77
"server": "node server",
8-
"client": "webpack && node webpack.server.js"
8+
"client": "webpack"
99
},
1010
"repository": {
1111
"type": "git",
@@ -33,6 +33,7 @@
3333
"babel-runtime": "^5.8.20",
3434
"react-transform-hmr": "^1.0.0",
3535
"webpack": "^1.11.0",
36-
"webpack-dev-server": "^1.10.1"
36+
"webpack-dev-middleware": "^1.2.0",
37+
"webpack-hot-middleware": "^2.2.0"
3738
}
3839
}

examples/universal/server/server.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import path from 'path';
44
import Express from 'express';
55
import qs from 'qs';
66

7+
import webpack from 'webpack';
8+
import webpackDevMiddleware from 'webpack-dev-middleware';
9+
import webpackHotMiddleware from 'webpack-hot-middleware';
10+
import webpackConfig from '../webpack.config';
11+
712
import React from 'react';
813
import { Provider } from 'react-redux';
914

@@ -14,6 +19,11 @@ import { fetchCounter } from '../common/api/counter';
1419
const app = new Express();
1520
const port = 3000;
1621

22+
// Use this middleware to set up hot module reloading via webpack.
23+
const compiler = webpack(webpackConfig);
24+
app.use(webpackDevMiddleware(compiler, { noInfo: true, publicPath: webpackConfig.output.publicPath }));
25+
app.use(webpackHotMiddleware(compiler, { log: console.log, path: '/__webpack_hmr', heartbeat: 10 * 1000 }));
26+
1727
// Use this middleware to server up static files built into dist
1828
app.use(require('serve-static')(path.join(__dirname, '../dist')));
1929

examples/universal/webpack.config.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,46 @@
11
var path = require('path');
22
var webpack = require('webpack');
3-
var host = 'localhost';
4-
var port = 3001;
53

64
module.exports = {
7-
devServerPort: port,
85
devtool: 'inline-source-map',
96
entry: [
10-
'webpack-dev-server/client?http://' + host + ':' + port,
11-
'webpack/hot/only-dev-server',
7+
'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000',
128
'./client/index.js'
139
],
1410
output: {
1511
path: path.join(__dirname, 'dist'),
1612
filename: 'bundle.js',
17-
publicPath: 'http://' + host + ':' + port + '/dist/'
13+
publicPath: '/dist/'
1814
},
1915
plugins: [
20-
new webpack.HotModuleReplacementPlugin()
16+
new webpack.optimize.OccurenceOrderPlugin(),
17+
new webpack.HotModuleReplacementPlugin(),
18+
new webpack.NoErrorsPlugin()
2119
],
2220
module: {
2321
loaders: [{
2422
test: /\.js$/,
25-
loaders: ['babel?optional=runtime'],
23+
loader: 'babel',
2624
exclude: /node_modules/,
27-
include: __dirname
25+
include: __dirname,
26+
query: {
27+
optional: ['runtime'],
28+
stage: 2,
29+
env: {
30+
development: {
31+
plugins: [
32+
'react-transform'
33+
],
34+
extra: {
35+
'react-transform': [{
36+
target: 'react-transform-hmr',
37+
imports: ['react'],
38+
locals: ['module']
39+
}]
40+
}
41+
}
42+
}
43+
}
2844
}]
2945
}
3046
};

examples/universal/webpack.server.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)