Giter Site home page Giter Site logo

kiki-le-singe / react-redux-universal-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
166.0 9.0 24.0 780 KB

An Universal ReactJS/Redux Boilerplate

License: MIT License

JavaScript 98.78% CSS 1.22%
react reactjs webpack babel redux hot-reload sass cssnext css-modules starterkit

react-redux-universal-boilerplate's Introduction

React Redux Universal Boilerplate

Introduction

I started this project to learn tools like React, Redux, Webpack, babeljs.io, ES6/ES2015... I did it mainly for fun. But it will be maintained and then I used it as Boilerplate for my React|Redux projects. So don't worry it works :p. It's not perfect but it works :).

Enjoy it! :)

An Universal ReactJS/Redux Boilerplate.

Requirements

Node >=7.6.0

Optional

Installation

$ git clone https://github.com/kiki-le-singe/react-redux-universal-boilerplate.git <name>
$ cd <name>
$ npm install or yarn
$ on postinstall you should choose between SASS or CSSNEXT

Run

  • npm start (dev mod)
  • npm run deploy (prod mod - Runs npm run build:client and npm run build:server scripts)
  • cd readyToDeploy, npm install or yarn then npm start (prod mod)

Some NPM Script Commands

Storybook

$ npm run storybook

Starts Storybook on `http://localhost:6006/``

Development

$ npm run setup

Allows to choose between sass or cssnext and clean up unnecessary files. This question you will be asked: You will use SASS as CSS extension language ๐Ÿ˜‰ . Do you wish to use CSSNEXT ๐Ÿ˜€ ? This choice is irreversible. Obviously you can install the project again or just use your version control system to discard changes in working directory.

This script runs on postinstall script (see package.json).

$ npm run dev

Serves your app at localip:3000. HMR will be enabled in development. A proxy is used for when you request http://localip:3000/, it will fetch http://localip:3001/ and return.

$ npm start

Runs npm run dev script.

$ npm run start:server

Starts the dev server with nodemon to serve your app at localip:3000.

$ npm run start:client:server

Starts the webpack dev server to serve your webpack bundle at localip:3001 and enable HMR in development.

Production

$ npm run build:client

It does some optimizations and compiles the client app, for the production, to disk (~/readyToDeploy/static/dist).

$ npm run build:server

It does some optimizations and compiles the server app, for the production, to disk (~/readyToDeploy/server.js).

$ npm run deploy

Runs npm run build:client and npm run build:server scripts.

$ cd readyToDeploy
$ npm install or yarn
$ npm start

Starts the prod server to serve your app at localip:3000.

Test

$ npm run test

Runs unit tests with Karma. It will generate a coverage report to ~/coverage.

$ npm run test:dev

Same as npm run test except it watches for changes to re-run tests.

Linter

$ npm run lint

Lint all files in ~/src and ~/__tests__.

Deployment

Runs npm run deploy and everything is in the ~/readyToDeploy folder.

You can read the README.

DEBUG

You should just install an extension Redux DevTools Extension. Personally I use Redux DevTools for Chrome

Are there any other alternatives? Sure! You can also use Redux DevTools. And there is also a small logger middleware redux-logger to log all actions and states after they are dispatched.

Features

Styles

CSSNEXT You can use .css file extensions using the latest CSS syntax with postcss-cssnext.

SASS You can use scss.|css file extensions using the sass syntax with sass.

CSS are automatically autoprefixed. You don't need to add prefixes like -webkit. See:

See the ~/src/common/styles/global directory to implement global styles (site's theme for example) and see an example of use case css module ~/src/common/views/AboutView. There is also a ~/src/common/styles/local directory for common local styles (this could allow to use css modules' composition between components).

Are there any other solutions ? Fortunately yes!

I could try one of these following options if what I implemented doesn't work very well...

  • It's possible to use css-modules for Theming
  • Obviously you can use the traditional method (it works very well) to do your own css or sass:
.foo-namespace {
  .baz {
    ...
  }
  .bar {
    ...
  }
}
<div className="foo-namespace">
  <div className="baz">baz</div>
  <div className="bar">bar</div>
</div>

Globals

These are global variables available to you anywhere in your source code. They can be found in ~/config/index.js.

new webpack.DefinePlugin({
  __CLIENT__: projectConfig.__CLIENT__,
  __SERVER__: projectConfig.__SERVER__,
  __DEV__: projectConfig.__DEV__,
  __PROD__: projectConfig.__PROD__,
})

Webpack is made for client side code development only. So we also have to define them on the server side

/**
 * Define isomorphic constants.
 */

// src/server/index.js

global.__CLIENT__ = false
global.__SERVER__ = true
global.__DEV__ = projectConfig.__DEV__
global.__PROD__ = projectConfig.__PROD__

Unit Tests

Tests are in ~/__tests__. Mocha will be used for structuring tests, karma as the test runner, Chai for assertions, Sinon.JS for spies... And Enzyme to simplify testing react components.

Tips

  • For the backend, if you want to ignore some modules, you can use the IgnorePlugin
new webpack.IgnorePlugin(/\.(css|less|scss|jpg|png|...)$/)

Message received from Webpack via terminal: WARNING in asset size limit: The following asset(s) exceed the recommended size limit (250 kB)

Sources

Learn more

react-redux-universal-boilerplate's People

Contributors

kiki-le-singe avatar vankhoawin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-redux-universal-boilerplate's Issues

CSS hot reloading

Hi, big thanks you for your boilerplate.
Does hot reloading not working right now in your boilerplate? Cuz I tested change body color and it's not reloaded, even after refresh the page. It applied after restart the app.

UPD. And on class names and Ids doesn't work hash in its names.
SS: https://cl.ly/0W0X1d1h2P3k

Redux Devtools extension error: window not defined

Hi! I started a new project using this boilerplate and am enjoying it so far! I did, however, run in to an issue while using the Redux DevTools Extension.

The exact error is:

  ReferenceError: window is not defined
      at configureStoreDev (/Users/vincentspeelman/Projects/TED/cinema/src/common/redux/store/configureStoreDev.js:14:7)
      at handleRender (/Users/vincentspeelman/Projects/TED/cinema/src/server/utils/index.js:28:17)
      at dispatch (/Users/vincentspeelman/Projects/TED/cinema/node_modules/koa-compose/index.js:43:32)
      at next (/Users/vincentspeelman/Projects/TED/cinema/node_modules/koa-compose/index.js:44:18)
      at createGenerator (/Users/vincentspeelman/Projects/TED/cinema/node_modules/koa-convert/index.js:24:16)
      at next (native)
      at Object.proxy (/Users/vincentspeelman/Projects/TED/cinema/node_modules/koa-proxy/index.js:26:23)
      at next (native)
      at onFulfilled (/Users/vincentspeelman/Projects/TED/cinema/node_modules/co/index.js:65:19)
      at /Users/vincentspeelman/Projects/TED/cinema/node_modules/co/index.js:54:5

I presume it's because configureStore.dev.js is referencing window:

  if (__DEBUG__) {
    finalCreateStore = compose(
      applyMiddleware(sagaMiddleware),
      window.devToolsExtension ? window.devToolsExtension() : f => f
    )(createStore);

Any idea how I can get this to stop erroring?

Thanks!

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.