Skip to content

🀘πŸ”₯ A barebones, ready-to-use universal/isomorphic starter kit for React + Redux

Notifications You must be signed in to change notification settings

alex-golovanov/universal-react-redux

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

universal-react-redux

A universal starter kit built with ES2015, react, react-router and redux. Server rendering with react and express. Bundled with Webpack, with HMR transforms and support for css-modules.

NOTE: This repository is meant to be continually updated to use the latest in the react ecosystem. It is meant to be more of a guiding template for you to customize and build your own universal apps with React and Redux. I do not promise that future updates will not break your existing application.

Get started

Install yarn if you don't have it already:

npm install -g yarn

Then copy environment variables and edit them if necessary:

cp .env.example .env

Then:

yarn install
yarn start

Direct your browser to http://localhost:3000.

For production builds:

yarn run prod:start

Note: pm2 must be installed to run production builds.

Directory Structure

β”œβ”€β”€ client                         # Client-side code
β”œβ”€β”€ common                         # Shared code between client and server
β”‚Β Β  β”œβ”€β”€ css
β”‚Β Β  β”œβ”€β”€ fonts
β”‚Β Β  β”œβ”€β”€ images
β”‚Β Β  β”œβ”€β”€ js
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ actions
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ components            # "Dumb" components
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ containers            # Smart containers
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ lib                   # Misc. libraries like helpers, etc.
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ middleware            # Middleware for redux
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ reducers              # Redux reducers
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ routes                # Routes each have an index.js which exports a react-router Route.
β”‚Β Β  β”‚Β Β  └── store                 # Store configuration for production and dev.
β”‚Β Β  └── layouts                   # Layout files to be rendered by the server.
β”œβ”€β”€ server                        # Server-side code
β”œβ”€β”€ webpack                       # Webpack configuration files

CSS Modules

This project uses CSS Modules. Class names should be in camelCase. Place the css file as a sibling to the component with the same name, for example:

β”œβ”€β”€ components
β”‚Β Β  β”œβ”€β”€ Header.js
β”‚Β Β  β”œβ”€β”€ Header.scss

Writing Tests

The default testing framework is Mocha, though you can use whatever you want. Make sure you have it installed:

npm install -g mocha

Tests should reside alongside the component/module/selector/etc that it is testing. For example:

β”œβ”€β”€ reducers
β”‚Β Β  β”œβ”€β”€ todos.js
β”‚Β Β  β”œβ”€β”€ todos.test.js

Tests can be written with ES2015, since it passes through babel-register.

Running Tests

To run a single test:

npm test /path/to/single.test.js

To run a directory of tests:

npm test /path/to/test/directory

To run all tests:

npm run test:all

This will run all files that are suffixed with a .test.js.

Running ESLint

npm run lint

Check the .eslintignore file for directories excluded from linting.

Changing the Asset Host

In production scenarios, you may want your assets to be hosted elsewhere besides on your server. Just set an environment variable to point the asset host to where ever you want, as defaults to localhost:3001. Just set it to the CDN of your choice.

If you're using Heroku:

heroku config:set ASSET_HOST=/dist/
# OR
heroku config:set ASSET_HOST=https://s3.amazonaws.com/mybucket/myasssets/

About

🀘πŸ”₯ A barebones, ready-to-use universal/isomorphic starter kit for React + Redux

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 92.2%
  • CSS 5.4%
  • HTML 2.4%