Git Product home page Git Product logo

isomorphic-react-template's Introduction

isomorphic-react-template

A starting template for building an isomorphic single page app using react.js on express with a Flux architecture.

Work in progress notice

This version does not include yet Flux. My efforts for making it working with Flux are in the reflux branch.

Main goals

  • React components are rendered on the server first, then mounted on the client.
  • Share the same routes server and client-side with react-router.
  • The initial state of the app can be fetched consuming REST APIs (in progress).
  • Make it working with a Flux architecture (in progress).
  • i18n made easy (todo)
  • Have a nice build script with cache busting.
  • Live development for React components with react-hot-loader and for scss.

Setup

# Clone the repository
git clone https://github.com/gpbl/isomorphic-react-template.git

# Install dependencies
cd isomorphic-react-template
npm install

# Run the development server
./scripts/dev

App structure

.
├── app.js         # Run the express server
│
├── server.jsx     # Send the server-rendered HTML document as response
├── client.jsx     # Entry point for the browser: mounts the <App /> component on document.body.
├── routes.jsx     # Define the react-router handlers 
│
├── cachebuster.js # Used by express in production for serving cache-busted URLs
│ 
├── components     # React's components container
│   ├── App.jsx    # The App component where the routes are mounted
│   ├── Html.jsx   # Renders the whole HTML document server side (via server.jsx)
│   ├── Index.jsx  # The "index" route (as example)
│   └── Place.jsx  # The "place" route (as example) 
│
├── style           # Container for .scss files
│
├── public          # Container for the static files. Cache-busted on build.
│
├── scripts
│   ├── dev        # Useful scripts to run the development server
│   └── prod       # ...or to test the production server
│
├── dev-tools.js   # Runs the webpack dev server, livereload, and watches for .scss changes
├── gulpfile.js    # Contains the gulp tasks for the build
│
├── webpack.config.js    			 # Webpack config for the build task
└── webpack.config.dev.js      # Webpack config for development

Development

Routes are a key part of the app: read the react-router documentation to understand how the routes handlers work. You change the routes in routes.jsx.

The main component is App.jsx. The <App /> component is mounted with client.jsx, which is the entry point for the browser.

If you have some questions feel free to open an issue in the project, since this template is still under development. :)

Running the development server

./scripts/dev
open http://localhost:3000
  • it watches for js changes with nodemon
  • it runs a webpack dev server with hot modules replacement for react components
  • it starts a livereload server watching the public files (install the browser extensions).

Building

The build task:

  1. compiles the client's js files with webpack
  2. compiles the main.scss file
  3. copies the app sources
  4. cache buster the public files
# Create a build in the /build directory
gulp build

# Test the production server on localhost:8080
PORT=8080 ./scripts/prod

Credits

The example app is inspired by the react-router examples.

isomorphic-react-template's People

Contributors

gpbl 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.