- Notifications
You must be signed in to change notification settings - Fork48
An npm package that lets you jump right into coding React and Redux with universal (isomorphic) rendering. Only manage Express setups or Webpack configurations if you want to.
License
bdefore/universal-redux
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This tool had a nice good run of things, but it's no longer recommended for greenfield projects. ConsiderCreate React App to be a currently maintained spiritual successor.
Universal Redux is an npm package that when used as a dependency in your project provides a universal (isomorphic) rendering server. You can either use its defaults and begin coding your project, or configure it to your liking with custom Webpack options and Express or Redux middleware. It's intended as both an easy starting point for developers new to React and Redux, as well as an extensible base by which advanced developers can augment with their own middleware and keep up to date with the fast-moving React ecosystem.
The quickest way to get started is to clone thestarter project. This gives you a base project that is set up with default configurations of Webpack and Express.
- An example with JWT authentication (Heroku demo)
- A refactor of react-redux-universal-hot-example with universal-redux and react-router-redux (Heroku demo)
- An example using Koa instead of Express
Your project must define a set of routes as specified by aReact Router configuration, but other than that, your folder structure and development path is up to you. Depending on your other dependencies, you may want to use a version of Universal Redux that is not the latest, using thesection below to decide.
Node.JS >= 4.1.1npm >= 3.3.12 (install vianpm install -g npm@3
if you are on Node 4)
npm install --save universal-redux
The configuration file in your project atconfig/universal-redux.config.js
defines what properties you want to customize. You can start by copying theannotated example. The configuration file is optional and is only necessary if you wish to modify default behavior.
Generally kept insrc/routes.js
, this is where you define what routes map to what views. Seeroutes.js
in the example project.
Any items specified in thewebpack.config
of your configuration will be merged with thedefault Webpack configuration. You may also turn onverbose
mode to see the exact Webpack configuration you are running.
You can add Express middleware by creating your own server.js like so:
import{express,renderer,start}from'universal-redux';importconfigfrom'../config/universal-redux.config.js';constapp=express(config);// app.use(someMiddleware);// app.use(someOtherMiddleware);app.use(renderer(config));start(app,config);
You will need to run this server.js instead of calling the default universal-redux-server.
Alternatively, you may create your own Express instance, add middleware beforehand and pass that instance as parameter when callinguniversal.app(app)
.
You can activate your own Redux middleware by specifying themiddleware
property in the configuration file. This must be a path to a file which exports each middleware as a function. All properties specified inglobals
will be available to the middleware.
Thehtml.head
configuration allows you to define your own<head>
that will be merged with the necessary items for serverside rendering. You can see an example of this in the JWT projecthere.
Alternatively, you can specifyhtml.root
in your configuration and this will be used instead of the default one. If you do take that approach, you'll want to be sure to include the items fromsrc/server/head.js
andsrc/server/body.js
.
You can add or override the defaultwebpack-isomorphic-tools configuration, by providing atoolsConfigPath
value to yourconfig.js
.
The following npm bin aliases have been defined:
universal-redux-watchuniversal-redux-serveruniversal-redux-build
You'll generally call these from the corresponding section of your project's scripts. Seepackage.json
in the example project.
Peer dependencies for each version:
"react": "^0.14.3","react-dom": "^0.14.3","react-router": "^1.0.0","redux-router": "^1.0.0-beta4"
"react": "^0.14.3","react-dom": "^0.14.3","react-router": "^1.0.0","redux-simple-router": "^1.0.1"
"react": "^0.14.3","react-dom": "^0.14.3","react-router": "^1.0.0","redux-simple-router": "^1.0.1"
Babel 6,React Router 2,React Router Redux 3 (Redux Simple Router renamed) is available but optional.
"react": "^0.14.3","react-dom": "^0.14.3","react-router": "^2.0.0-rc4",
Babel 6,React Router 2,React Router Redux 3 (Redux Simple Router renamed) is available but optional.
"react": "^15.0.0","react-dom": "^15.0.0","react-router": "^2.0.0",
If you'd like to develop on Universal Redux, clone the repo and while testing with a project that uses it, you can runPROJECT_PATH=/path/to/project npm run dev
from the Universal Redux root, which will watch for changes and copy them over to your project'snode_modules/universal-redux/lib
directory. If any of your changes add dependencies, you will need to copy those over manually.
This project forked off ofreact-redux-universal-hot-example. Please refer to the README there for more details and join the discussion at thepull request.
About
An npm package that lets you jump right into coding React and Redux with universal (isomorphic) rendering. Only manage Express setups or Webpack configurations if you want to.