Coder Social home page Coder Social logo

joehua87 / universal-redux Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bdefore/universal-redux

0.0 2.0 0.0 4.13 MB

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: MIT License

JavaScript 95.38% Shell 4.62%

universal-redux's Introduction

Universal Redux

npm version build status Dependency Status devDependency Status Demo on Heroku Discord

What and Why

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.

Getting Started

The quickest way to get started is to clone the starter project. This gives you a base project that is set up with default configurations of Webpack and Express.

Other Examples

Usage

Your project must define a set of routes as specified by a React 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 the section below to decide.

Requirements

Node.JS >= 4.1.1 npm >= 3.3.12 (install via npm install -g npm@3 if you are on Node 4)

Install

npm install --save universal-redux

Customization

The configuration file in your project at config/universal-redux.config.js defines what properties you want to customize. You can start by copying the annotated example. The configuration file is optional and is only necessary if you wish to modify default behavior.

Routes

Generally kept in src/routes.js, this is where you define what routes map to what views. See routes.js in the example project.

Webpack configuration

Any items specified in the webpack.config of your configuration will be merged with the default Webpack configuration. You may also turn on verbose mode to see the exact Webpack configuration you are running.

Express middleware

You can add your own Express middleware like so:

import { express, renderer, start } from 'universal-redux';
import config from '../config/universal-redux.config.js';

const app = express(config);

// app.use(someMiddleware);
// app.use(someOtherMiddleware);

app.use(renderer(config));
start(app, config);

Alternatively, you may create your own Express instance, add middleware beforehand and pass that instance as parameter when calling universal.app(app).

Redux middleware

You can activate your own Redux middleware by specifying the middleware property in the configuration file. This must be a path to a file which exports each middleware as a function. On serverside renders, those functions will be called with two parameters: the Express request and response objects. On clientside renders, they will be called with none. All properties specified in globals will be available to the middleware.

Adding your own items to HTML head

The html.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 project here.

Alternatively, you can specify html.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 from src/server/head.js and src/server/body.js.

Webpack Isomorphic Tools configuration

You can add or override the default webpack-isomorphic-tools configuration, by providing a toolsConfigPath value to your config.js.

Scripts

The following npm bin aliases have been defined:

universal-redux-watch
universal-redux-server
universal-redux-build

You'll generally call these from the corresponding section of your project's scripts. See package.json in the example project.

What version to use

Peer dependencies for each version:

0.x

Babel 5, Redux Router

"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-router": "^1.0.0",
"redux-router": "^1.0.0-beta4"

1.x

Babel 5, Redux Simple Router

"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-router": "^1.0.0",
"redux-simple-router": "^1.0.1"

2.x

Babel 6, Redux Simple Router

"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-router": "^1.0.0",
"redux-simple-router": "^1.0.1"

3.x (Beta - dependencies may change)

Babel 6, React Router 2, Redux Simple Router 2

"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-router": "^2.0.0-rc4",
"redux-simple-router": "^2.0.0"

Local development

If you'd like to develop on Universal Redux, clone the repo and while testing with a project that uses it, you can run PROJECT_PATH=/path/to/project npm run dev from the Universal Redux root, which will watch for changes and copy them over to your project's node_modules/universal-redux/lib directory. If any of your changes add dependencies, you will need to copy those over manually.

Inspirations

This project forked off of react-redux-universal-hot-example. Please refer to the README there for more details and join the discussion at the pull request.

universal-redux's People

Contributors

alexanderchan avatar arkist avatar ashtonsix avatar austinpray avatar b2whats avatar bdefore avatar benoitvallon avatar catamphetamine avatar dts avatar erikras avatar gaearon avatar greenkeeperio-bot avatar guilhermesad avatar istravis avatar joehua87 avatar justingreenberg avatar korczis avatar lemoncms avatar leonli avatar markus-ipse avatar mhodgson avatar msikma avatar nicolabortignon avatar nogsmpls avatar quicksnap avatar snowcxt avatar stevoland avatar swordsreversed avatar trueter avatar yuters avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.