Skip to content

Commit 7387504

Browse files
committed
Modernize async example setup
1 parent 0a5ea48 commit 7387504

File tree

11 files changed

+86
-103
lines changed

11 files changed

+86
-103
lines changed

examples/async/.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"presets": ["es2015", "react"],
2+
"presets": ["es2015-webpack", "react"],
33
"plugins": ["transform-object-rest-spread"]
44
}

examples/async/devServer.js

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

examples/async/index.html

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

examples/async/package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "redux-async-example",
33
"description": "Redux async example",
44
"scripts": {
5-
"start": "node devServer.js"
5+
"start": "node server.dev.js",
6+
"build": "webpack --config webpack.config.prod.js"
67
},
78
"repository": {
89
"type": "git",
@@ -21,17 +22,17 @@
2122
"redux-thunk": "^1.0.3"
2223
},
2324
"devDependencies": {
24-
"babel-cli": "^6.10.1",
2525
"babel-core": "^6.3.15",
2626
"babel-loader": "^6.2.0",
2727
"babel-plugin-transform-object-rest-spread": "^6.8.0",
28-
"babel-preset-es2015": "^6.3.13",
28+
"babel-preset-es2015-webpack": "^6.4.1",
2929
"babel-preset-react": "^6.3.13",
3030
"expect": "^1.6.0",
3131
"express": "^4.13.3",
32+
"html-webpack-plugin": "^2.20.0",
3233
"node-libs-browser": "^0.5.2",
33-
"webpack": "^1.9.11",
34-
"webpack-dev-middleware": "^1.2.0",
35-
"webpack-hot-middleware": "^2.9.1"
34+
"webpack": "^2.1.0-beta.13",
35+
"webpack-dev-middleware": "^1.6.1",
36+
"webpack-hot-middleware": "^2.10.0"
3637
}
3738
}

examples/async/server.dev.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const webpack = require('webpack')
2+
const express = require('express')
3+
const webpackDevMiddleware = require('webpack-dev-middleware')
4+
const webpackHotMiddleware = require('webpack-hot-middleware')
5+
const config = require('./webpack.config.dev')
6+
7+
const app = express()
8+
const port = 3000
9+
const compiler = webpack(config)
10+
11+
app.use(webpackDevMiddleware(compiler, {
12+
noInfo: true,
13+
publicPath: config.output.publicPath
14+
}))
15+
app.use(webpackHotMiddleware(compiler))
16+
17+
app.listen(port, (error) => {
18+
if (error) {
19+
console.error(error)
20+
} else {
21+
console.info('🌎 Open http://localhost:%s/ in a web browser', port)
22+
}
23+
})

examples/async/src/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ import { render } from 'react-dom'
44
import Root from './components/Root'
55
import configureStore from './store/configureStore'
66

7+
const rootEl = document.createElement('div')
8+
document.body.appendChild(rootEl)
9+
710
const store = configureStore()
11+
render(<Root store={store} />, rootEl)
812

9-
render(
10-
<Root store={store} />,
11-
document.getElementById('root')
12-
)
13+
if (module.hot) {
14+
module.hot.accept('./components/Root', () => {
15+
render(<Root store={store} />, rootEl)
16+
})
17+
}

examples/async/src/store/configureStore.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ export default function configureStore() {
1212
if (module.hot) {
1313
// Enable Webpack hot module replacement for reducers
1414
module.hot.accept('../reducers', () => {
15-
const nextRootReducer = require('../reducers').default
16-
store.replaceReducer(nextRootReducer)
15+
store.replaceReducer(reducer)
1716
})
1817
}
1918

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var path = require('path')
2+
var webpack = require('webpack')
3+
var HtmlWebpackPlugin = require('html-webpack-plugin');
4+
5+
module.exports = {
6+
devtool: 'cheap-module-eval-source-map',
7+
entry: ['./src/index', 'webpack-hot-middleware/client'],
8+
plugins: [
9+
new webpack.HotModuleReplacementPlugin(),
10+
new HtmlWebpackPlugin({ title: 'Redux async example' }),
11+
new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"development"' })
12+
],
13+
module: {
14+
loaders: [{
15+
test: /\.js$/,
16+
loaders: ['babel'],
17+
include: path.join(__dirname, 'src')
18+
}]
19+
}
20+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var path = require('path')
2+
var webpack = require('webpack')
3+
var HtmlWebpackPlugin = require('html-webpack-plugin');
4+
5+
module.exports = {
6+
entry: './src/index',
7+
output: {
8+
path: path.join(__dirname, 'dist'),
9+
filename: '[name].[hash].js',
10+
publicPath: '/'
11+
},
12+
plugins: [
13+
new HtmlWebpackPlugin({ title: 'Redux async example' }),
14+
new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"production"' }),
15+
new webpack.optimize.OccurrenceOrderPlugin(),
16+
new webpack.optimize.UglifyJsPlugin()
17+
],
18+
module: {
19+
loaders: [{
20+
test: /\.js$/,
21+
loaders: ['babel'],
22+
include: path.join(__dirname, 'src')
23+
}]
24+
}
25+
}

examples/async/webpack.dev.config.js

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

0 commit comments

Comments
 (0)