Skip to content

Commit 40aaaf1

Browse files
committed
Merge pull request reduxjs#640 from timdorr/the-universe-stands-alone
Add universal to examples and update webpack config
2 parents 4d5d2d5 + ba8529f commit 40aaaf1

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

docs/introduction/Examples.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,26 @@ It covers:
6464
* Caching responses and showing a spinner while data is fetching;
6565
* Invalidating the cached data.
6666

67+
## Universal
68+
69+
Run the [Universal](https://github.com/rackt/redux/tree/master/examples/universal) example:
70+
71+
```
72+
git clone https://github.com/rackt/redux.git
73+
74+
cd redux/examples/universal
75+
npm install
76+
npm start & npm run client
77+
78+
open http://localhost:8080/
79+
```
80+
81+
It covers:
82+
83+
* [Universal rendering](/docs/recipes/ServerRendering.md) with Redux and React
84+
* Prefetching state based on input and via asynchronous fetches.
85+
* Passing state from the server to the client
86+
6787
## Real World
6888

6989
Run the [Real World](https://github.com/rackt/redux/tree/master/examples/real-world) example:

examples/universal/webpack.config.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,28 @@ module.exports = {
1919
new webpack.HotModuleReplacementPlugin(),
2020
new webpack.NoErrorsPlugin()
2121
],
22-
resolve: {
23-
alias: {
24-
'redux': path.join(__dirname, '..', '..', 'src')
25-
},
26-
extensions: ['', '.js']
27-
},
2822
module: {
2923
loaders: [{
3024
test: /\.js$/,
3125
loaders: ['react-hot', 'babel?optional=runtime'],
3226
exclude: /node_modules/,
3327
include: __dirname
34-
}, {
35-
test: /\.js$/,
36-
loaders: ['babel'],
37-
include: path.join(__dirname, '..', '..', 'src')
3828
}]
3929
}
4030
};
31+
32+
// When inside Redux repo, prefer src to compiled version.
33+
// You can safely delete these lines in your project.
34+
var reduxSrc = path.join(__dirname, '..', '..', 'src');
35+
var reduxNodeModules = path.join(__dirname, '..', '..', 'node_modules');
36+
var fs = require('fs');
37+
if (fs.existsSync(reduxSrc) && fs.existsSync(reduxNodeModules)) {
38+
// Resolve Redux to source
39+
module.exports.resolve = { alias: { 'redux': reduxSrc } };
40+
// Compile Redux from source
41+
module.exports.module.loaders.push({
42+
test: /\.js$/,
43+
loaders: ['babel'],
44+
include: reduxSrc
45+
});
46+
}

0 commit comments

Comments
 (0)