All Projects โ†’ manuelbieh โ†’ React Ssr Setup

manuelbieh / React Ssr Setup

Licence: mit
React Starter Project with Webpack 4, Babel 7, TypeScript, CSS Modules, Server Side Rendering, i18n and some more niceties

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Ssr Setup

Reeakt
A modern React boilerplate to awesome web applications
Stars: โœญ 116 (-82.89%)
Mutual labels:  webpack, hmr, eslint, prettier, express, react-router
React Cool Starter
๐Ÿ˜Ž ๐Ÿฃ A starter boilerplate for a universal web app with the best development experience and a focus on performance and best practices.
Stars: โœญ 1,083 (+59.73%)
Mutual labels:  webpack, prettier, express, react-router, postcss, css-modules
Express React Boilerplate
๐Ÿš€๐Ÿš€๐Ÿš€ This is a tool that helps programmers create Express & React projects easily base on react-cool-starter.
Stars: โœญ 32 (-95.28%)
Mutual labels:  webpack, eslint, prettier, babel, express, react-router
Pwa
An opinionated progressive web app boilerplate
Stars: โœญ 353 (-47.94%)
Mutual labels:  webpack, eslint, babel, react-router, postcss
React Pages Boilerplate
Deliver react + react-router application to gh-pages
Stars: โœญ 134 (-80.24%)
Mutual labels:  webpack, eslint, babel, react-router, css-modules
React Redux Saucepan
A minimal and universal react redux starter project. With hot reloading, linting and server-side rendering
Stars: โœญ 86 (-87.32%)
Mutual labels:  eslint, prettier, babel, express, react-router
React Redux Universal Boilerplate
An Universal ReactJS/Redux Boilerplate
Stars: โœญ 165 (-75.66%)
Mutual labels:  webpack, eslint, babel, react-router, css-modules
Js Stack Boilerplate
Final boilerplate code of the JavaScript Stack from Scratch tutorial โ€“
Stars: โœญ 145 (-78.61%)
Mutual labels:  webpack, eslint, babel, express, react-router
Express Webpack React Redux Typescript Boilerplate
๐ŸŽ‰ A full-stack boilerplate that using express with webpack, react and typescirpt!
Stars: โœญ 156 (-76.99%)
Mutual labels:  webpack, eslint, babel, express, react-router
React
Extremely simple boilerplate, easiest you can find, for React application including all the necessary tools: Flow | React 16 | redux | babel 6 | webpack 3 | css-modules | jest | enzyme | express + optional: sass/scss
Stars: โœญ 244 (-64.01%)
Mutual labels:  webpack, babel, express, react-router, css-modules
Budgeting
Budgeting - React + Redux + Webpack (tree shaking) Sample App
Stars: โœญ 971 (+43.22%)
Mutual labels:  webpack, eslint, prettier, babel, react-router
React Starter Kit
React, Redux, Webpack, Material UI, Boostrap 4, Code Splitting, HMR
Stars: โœญ 229 (-66.22%)
Mutual labels:  webpack, hmr, eslint, prettier, babel
Starter React Flux
Generate your React PWA project with TypeScript or JavaScript
Stars: โœญ 65 (-90.41%)
Mutual labels:  webpack, eslint, prettier, babel, react-router
Mostly
They mostly come at night; mostly.
Stars: โœญ 78 (-88.5%)
Mutual labels:  webpack, eslint, prettier, babel, express
Static Site Boilerplate
A better workflow for building modern static websites.
Stars: โœญ 1,633 (+140.86%)
Mutual labels:  webpack, eslint, babel, postcss
Webpack React Boilerplate
Minimal React 16 and Webpack 4 boilerplate with babel 7, using the new webpack-dev-server, react-hot-loader, CSS-Modules
Stars: โœญ 358 (-47.2%)
Mutual labels:  eslint, prettier, babel, css-modules
Book
ใ€Š็ŽฐไปฃๅŒ–ๅ‰็ซฏๅทฅ็จ‹ๅธˆๆƒๅจๆŒ‡ๅ—ใ€‹https://guoyongfeng.github.io/book/
Stars: โœญ 141 (-79.2%)
Mutual labels:  webpack, eslint, babel, postcss
React Redux Auth0 Kit
Minimal starter boilerplate project with CRA, React, Redux, React Router and Auth0 authentication
Stars: โœญ 115 (-83.04%)
Mutual labels:  webpack, eslint, babel, react-router
Project Webcube
Continuously updated JS infrastructure for modern web dev
Stars: โœญ 141 (-79.2%)
Mutual labels:  webpack, eslint, babel, react-router
Sku
Front-end development toolkit
Stars: โœญ 403 (-40.56%)
Mutual labels:  webpack, eslint, babel, css-modules

โš› React + Express โ€“ SSR Setup with TypeScript

Maintainability dependencies Status Known Vulnerabilities styled with prettier CircleCI

Advertising: I wrote a book about React. There's a German and an English version. Buy one if you like this project and you want to support my work!

English German
English German

New! You can now use this project as template! Click here to create a new repo on GitHub with this project as template.

TOC

Motivation

This is just another React Starter Project as there are literally hundreds of others out there. The reason I created this one was to have one central repo I can base my own future projects on, which contains most of the packages I usually use, is easily extendable, easy to understand, supports server side rendering, and uses all the configs and settings I made good experiences with in the past.

Another reason I created my own starter project was because I was setting up two new long term projects and I wanted to be able to use Webpack 4 and Babel 7 long before it was stable. None of the bigger and well known starter projects were supporting both by the time I created this starter project. So the idea was born to create my very own. And here we are ๐ŸŽ‰

A few things might be familiar when you've worked with other starter projects before. I borrowed many ideas (and will continue to do so) from Create React App, React Starter Kit and other great starter projects because my intention was to create an up-to-date starter project for myself based on best practices and not to completely reinvent the wheel in every possible way just for the sake of it.

Goals

My goal is to provide a well-tested, regularly maintained, easily configurable and adjustable React Starter Project with support for server side rendering that gives you a good basis to start your own project on. As minimal as possible with as much functionality as necessary.

I use this Starter Project in several real-word projects so it is battle-tested and everytime I fix a bug or add a feature I find useful I will also update this Starter Project. I will also keep the dependencies up-to-date on a regular basis and will also stay updated with all the latest and greatest best practices in the React world and integrate them if possible and useful!

If you have any questions you can always open an issue on Github or reach out to me on Twitter!

Features

This project has out-of-the-box support for the following things:

  • General Setup

    • ๐Ÿ”ฅ Babel 7
    • ๐Ÿ“ฆ Webpack 4
    • ๐Ÿ”ฅ ESLint 7 (with a set of custom rules which may be mostly identical to AirBnB with some personal flavor added)
    • ๐Ÿ”ฅ TypeScript (via Babel)
    • ๐Ÿ”ฅ Prettier
    • ๐Ÿ”ฅ Jest
    • ๐Ÿ React Testing Library
    • โœ… React i18next for multi language support
    • โœ… Server Side Rendering with Express
    • ๐ŸŽ React Fast Refresh
    • โœ… CSS Modules
    • โœ… PostCSS
    • โœ… Precommit hooks via lint-staged + Husky
    • โœ… Optional static build without the need for Node.js on the server
    • ๐Ÿ“• Support for Storybook (>= 5.0.0)
  • Libs and Dependencies

    • โœ… React i18next for multi language support
    • โš› React 16.x (latest), with Hooks!
    • โœ… Redux + Thunk middleware
    • โœ… Immer
    • โœ… Reselect
    • โœ… React Router 5
    • โœ… React Helmet

Since it's only using standard APIs so far it is ready to be used with the new React Suspense feature coming in React 17!

Installation

As a general recommendation you should create a fork of this project first or use GitHub's use this template function so you can adjust it to your own needs, add all the dependencies you need and commit everything back into your own repository.

Once you've forked the repository here on Github, clone it, cd into the directory and run yarn (or npm install) on your command line to install all the dependencies. You're ready to go now!

Usage

There are npm scripts for all the relevant things. The server will always be started on port 8500 unless otherwise specified in process.env.PORT. You can use a .env file to specify env vars. If you want to use them in your client side code, don't forget to add them in config/env.js.

Noteworthy scripts:

yarn start

Starts the app in development mode: creates a new client and server dev build using webpack, starts the Express server build (for both file serving and server side pre-rendering) and keeps webpack open in watchmode. Updates the app (if possible) on change using HMR.

yarn build

Creates a new build, optimized for production. Does not start a dev server or anything else.

yarn test

Run all tests using jest.

yarn test:update

Update all Jest snapshots (if there are any)

yarn lint:js

Run ESLint for all JavaScript and TypeScript files

yarn lint:css

Run Stylelint for all CSS files

yarn lint

Run lint:js and lint:css in parallel

yarn analyze

Starts webpack-bundle-analyzer to give you the opportunity to analyze your bundle(s)

yarn depgraph

Creates an image of your dependency graph. Requires GraphVIZ to be in your system's PATH

yarn plop

Run plop to create new React components or Redux reducers via CLI

Environment Variables

There are a few environment variables you can set to adjust the setup to your needs

Variable Default Description
PORT 8500 Port number your application will be served on.
HOST http://localhost Host (including protocol!) your application will be served on. This is usually neglectable as most of the time your application will be served via remote proxy (e.g. Nginx) on localhost. Note: this is only for convenience. The server itself will not be bound exclusively to that host.
DEVSERVER_HOST http://localhost Optional. Different host for the Webpack Dev Server to be served on.

Tricks

Client side version (opt-in)

Beginning with v1.3.0, a static index.html is also generated and written to your clientBuild directory. You are now able to deploy the build/client directory to a static webhost (such as Netlify or AWS S3) and serve your application from there!

For the generation of the index.html the server side build gets started right after building, a headless Chrome then visits the site and writes the content of the server side response to your client directory. So you still need the src/server directory and the server side build but you're now flexible and can decide on your own whether you want to have the full server side experience or only deploy your completely static app somewhere.

Component scaffolding using plop

Along with this starter kit comes plop - a great command line tool to keep the structure of your Redux components and Redux reducers consistent. Run yarn plop (or npm run plop) to have components and Redux reducers created for you automatically! Just enter a name, answer a few questions and you're ready to go! You can of course adjust everything to your needs. All Plop templates can be found in the config/plop directory.

๐Ÿ“• Storybook support

I've successfully tested Storybook and it integrates seamlessly and without any issues into this setup. If you want to add Storybook to your project, install Storybook ^4.0.0 and run getstorybook to have the basic setup created for you. You must then replace all the content in .storybook/webpack.config.js with the following line:

module.exports = require('../config/webpack.config.js/storybook');

Afterwards you should be able to run yarn storybook to start the Storybook Dev Server.

Keep your project up to date

If you want your project to stay up to date with recent changes to this project, you can add React SSR Starter as remote to your local git repo. Use the following line:

git remote add upstream [email protected]:manuelbieh/react-ssr-setup.git

More on that can be found on Github: Syncing a fork.

Avoid source map generation for faster builds

In some cases you might not want to generate source maps for the generated files. In this case you can set the OMIT_SOURCEMAP environment variable to true. No source map files will be generated then. This works no matter if you're in devmode or building for production.

Change the port of the dev environment

By default if you run yarn start the development server will use port 8500. You can change this by specifying a PORT environment variable.

Import SVGs as ReactComponent

You can import SVG files as React components exactly the way you can do it in Create React App 2.0:

import { ReactComponent as Logo } from './Logo.svg';

Then you can use it in JSX like <div><Logo /></div>.

Here is a video that explains that a bit more.

Caveats

  • [1] MiniCSSExtractPlugin doesn't play nicely with consecutive builds in Webpack's watchmode yet (Github issue here). So I'm using ExtractTextWebpackPlugin until this is fixed Fixed! 490e6e9
  • [2] Hot Module Replacement is still a bit buggy. Not all components have been configured and updated to play nicely with HMR (namely Redux and React-Router) Seems to be fixed (still validating) 66875a1
  • Running the build in production: I strongly recommend to serve your static assets using Nginx or Apache instead of the Express.static middleware. That's how I usually do it and that's why you won't see any assets when starting the production server build with Node. If you still want to use Express.static in production despite the warning, have a look at the first few lines of ./src/server/index.js. There's a short comment with a description what you need to do.

Todo

  • [x] Replace ExtractTextWebpackPlugin with MiniCSSExtractPlugin once it's working properly
  • [x] Get HMR working (done, mostly)
  • [x] Add HMR for Redux
  • [x] Add HMR for CSS Modules (depends a bit on MiniCSSExtractPlugin) (using ExtractTextWebpackPlugin)
  • [ ] Add React Error Overlay from Create-React-App
  • [x] Add react-loadable or react-universal-component (or both, still investigating what makes most sense). Update: react-loadable is out due to questionable license change Just use React.lazy which was introduced in React 16.6.
  • [x] Improve server side template
  • [x] Add (and use) react-helmet
  • [ ] Add/improve server side chunk loading - Wait for the new React Fizz Renderer to land
  • [x] Add test setup using Jest
  • [ ] Add optimize-css-assets-webpack-plugin and postcss-safe-parser similar to how CRA 2 is doing it
  • [x] Modify svg-loader babel-loader so SVGs can be imported as React component (see CRA 2)
  • [ ] Add proper offline support using Workbox
  • [ ] Document i18n functionality (scan, pull, push, ...)
  • [ ] Move i18n scripts to an external package to clean up the dependency tree
  • [ ] Fine tuning different minor things (ongoing task)

Changelog

Moved to its own file: CHANGELOG.md

License

MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].