├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── lib ├── app-emulation.js ├── cli.js ├── main.js ├── webpack-base-config.js ├── webpack-dev-config.js └── webpack-prod-config.js ├── package-lock.json ├── package.json ├── templates ├── .eslintrc.json └── tiny-todos │ └── src │ ├── client │ ├── App.jsx │ ├── index.html │ ├── index.js │ └── reducer.js │ └── server │ └── index.js └── tests ├── cli.test.js ├── files └── src │ └── client │ ├── App.jsx │ ├── index.html │ ├── index.js │ └── reducer.js └── middleware.test.js /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.swp 3 | npm-debug.log 4 | node_modules 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 6 4 | - 7 5 | - 8 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [Unreleased] 4 | 5 | ## [0.5.2] - 2017-11-24 6 | ### Changed 7 | - fix exclude option in webpack config, again 8 | 9 | ## [0.5.1] - 2017-11-24 10 | ### Changed 11 | - fix exclude option in webpack config 12 | 13 | ## [0.5.0] - 2017-11-24 14 | ### Changed 15 | - update npm packages 16 | - use babel 7 17 | 18 | ## [0.4.1] - 2017-11-24 19 | ### Added 20 | - option to exclude `node_modules` in webpack config 21 | - include package-lock.json 22 | 23 | ## [0.4.0] - 2017-09-18 24 | ### Added 25 | - option for pre server-side rendering hook (#8) 26 | 27 | ## [0.3.1] - 2017-09-07 28 | ### Changed 29 | - fix babel-preset-env option 30 | 31 | ## [0.3.0] - 2017-09-07 32 | ### Added 33 | - option for server-side rendering for `/` (#7) 34 | 35 | ### Changed 36 | - update npm packages 37 | - use babel-preset-env 38 | 39 | ## [0.2.1] - 2017-02-14 40 | ### Changed 41 | - server-side rendering HMR support 42 | 43 | ## [0.2.0] - 2017-02-13 44 | ### Added 45 | - add react-router 46 | - server-side rendering 47 | 48 | ### Changed 49 | - update npm packages 50 | 51 | ## [0.1.1] - 2017-01-24 52 | ### Added 53 | - Support for hot module replacement 54 | 55 | ### Changed 56 | - update webpack 2.2.0 57 | - webpack production build 58 | 59 | ## [0.1.0] - 2017-01-20 60 | ### Added 61 | - Initial release 62 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Daishi Kato 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # express-react-redux 2 | 3 | [![Build Status](https://travis-ci.org/dai-shi/express-react-redux.svg?branch=master)](https://travis-ci.org/dai-shi/express-react-redux) 4 | [![npm](https://img.shields.io/npm/v/express-react-redux.svg)](https://www.npmjs.com/package/express-react-redux) 5 | 6 | Express middleware for React/Redux applications 7 | 8 | ## Motivation 9 | 10 | For beginners, building a development environment for a React/Redux app 11 | is a time-consuming task, while they want to start to coding an app. 12 | To this end, there are various packages that support building React/Redux apps. 13 | However, I wasn't able to find one that fulfills my requirements: 14 | 15 | - It's provided as a library not as a tool nor a boilerplate. 16 | - It can be used not only for learning but for production. 17 | - It's not a blackbox, but can be used for learning how it works. 18 | - It should be customizable if you learn enough. 19 | 20 | Hence, I decided to create yet another pakcage for the same purpose. 21 | This package is express middleware with the assumption that server 22 | logic is implemented in express and express provides APIs to the client app. 23 | Let's call it an Express/React/Redux app. 24 | 25 | ## What is this 26 | 27 | This is simple express middleware that comes with 28 | a default opinionated webpack config. 29 | It provides some functionalities by default: 30 | 31 | - babel transformation (latest+stage3) 32 | - hot module replacement 33 | - server side rendering 34 | 35 | ## How to use 36 | 37 | create an app folder: 38 | 39 | ``` 40 | mkdir sample-app 41 | cd sample-app 42 | npm init 43 | ``` 44 | 45 | install packages: 46 | 47 | ``` 48 | npm install express express-react-redux --save 49 | ``` 50 | 51 | import a template app: 52 | 53 | ``` 54 | $(npm bin)/express-react-redux import tiny-todos 55 | ``` 56 | 57 | run a dev server: 58 | 59 | ``` 60 | PORT=3000 npm start 61 | ``` 62 | 63 | build and run a production server: 64 | 65 | ``` 66 | npm run build 67 | PORT=3000 NODE_ENV=production npm start 68 | ``` 69 | 70 | ## Similar Projects 71 | 72 | - https://github.com/insin/nwb 73 | - https://github.com/petehunt/rwb 74 | - https://github.com/facebookincubator/create-react-app 75 | -------------------------------------------------------------------------------- /lib/app-emulation.js: -------------------------------------------------------------------------------- 1 | // emulating express middleware 2 | const app = { 3 | stack: [], 4 | use: func => app.stack.push(func), 5 | get: (url, func) => app.stack.push((req, res, next) => { 6 | if (req.method === 'get' && req.url === url) { 7 | func(req, res, next); 8 | } else { 9 | next(); 10 | } 11 | }), 12 | handle: (index, req, res, next) => { 13 | if (app.stack[index]) { 14 | app.stack[index](req, res, err => 15 | (err ? next(err) : app.handle(index + 1, req, res, next))); 16 | } else { 17 | next(); 18 | } 19 | }, 20 | }; 21 | 22 | module.exports = app; 23 | -------------------------------------------------------------------------------- /lib/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const path = require('path'); 4 | const program = require('commander'); 5 | const copyfiles = require('copyfiles'); 6 | const json = require('json'); 7 | 8 | program 9 | .command('import