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.
Node
>=7.6.0
$ 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
- 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)
$ npm run storybook
Starts Storybook on `http://localhost:6006/``
$ 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.
$ 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
.
$ 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.
$ npm run lint
Lint all files in ~/src
and ~/__tests__
.
Runs npm run deploy
and everything is in the ~/readyToDeploy
folder.
You can read the README.
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.
- react
- redux
- redux-devtools-extension
- react-router 4
- react-router-redux
- react-helmet
- React Hot Loader 3
- webpack 2
- webpack-dev-middleware
- webpack-hot-middleware
- webpack-isomorphic-tools
- image-webpack-loader
- purifycss-webpack-plugin
- babel
- koa 2
- eslint
- Universal (Isomorphic)
- normalize.css
- postcss-cssnext
- sass
- css-modules
- karma
- Mocha
- Chai
- Sinon.JS
- Enzyme
- why-did-you-update
- babel-preset-latest
- Backend bundle with webpack
- Code Splitting ( ** for now doesn't work with React Router 4. You can use an old version of this starter
2.0.5
** ) - Storybook
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:
- automatic vendor prefixes from
postcss-cssnext features
- Autoprefixer (used for sass mode)
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
forTheming
- 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>
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__
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.
- For the backend, if you want to ignore some modules, you can use the IgnorePlugin
new webpack.IgnorePlugin(/\.(css|less|scss|jpg|png|...)$/)
- How to reduce the size of vendor's bundle? Maybe should we use some librairies as extarnals? See library-and-externals and React - using-a-cdn
Message received from Webpack via terminal: WARNING in asset size limit: The following asset(s) exceed the recommended size limit (250 kB)
- React Redux Universal Hot Example
- webapp (React, Redux, React-router, i18n, isomorphic, etc)
- Universal React Boilerplate
- React Universal example
- React Simple Universal
- React Isomorphic Starterkit
- React Redux Starter Kit
- react-boilerplate - Boilerplate for "SurviveJS - React"
- react-testing-starter-kit
- karma-webpack
- react-cool-starter
- isomorphic-flux-boilerplate
- meatier
- Babel Handbook
- css-modules
- css-modules' webpack-demo
- css-loader's local-scope
- Run multiple commands in parallel:
- Concurrently
- npm-run-all
- html5-boilerplate
- yarn
- Getting Started
- Documentation
- Migrating from npm
- koajs tutorial
- webpack official
- webpack tutorial from survivejs
- Getting Started with Webpack 2
- webpack-2-tree-shaking-configuration
- Backend-Apps-with-Webpack
- complete-intro-to-react
- Progressive Web Apps with React.js from Addy Osmani