Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tomtom94/react-easy-ssr
🔥 React Starter Project with Webpack 5, Babel 7, TypeScript, Redux-saga, Styled-components, React-jss, Split code, Server Side Rendering.
https://github.com/tomtom94/react-easy-ssr
babel7 loadable-components react react-jss redux-saga ssr styled-components typescript webpack5
Last synced: 3 months ago
JSON representation
🔥 React Starter Project with Webpack 5, Babel 7, TypeScript, Redux-saga, Styled-components, React-jss, Split code, Server Side Rendering.
- Host: GitHub
- URL: https://github.com/tomtom94/react-easy-ssr
- Owner: tomtom94
- License: mit
- Created: 2020-11-24T15:30:06.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-01-26T12:47:12.000Z (10 months ago)
- Last Synced: 2024-05-12T01:34:01.137Z (6 months ago)
- Topics: babel7, loadable-components, react, react-jss, redux-saga, ssr, styled-components, typescript, webpack5
- Language: TypeScript
- Homepage: https://reacteasyssrjckf9fbl-reacteasyssrfront.functions.fnc.fr-par.scw.cloud
- Size: 3.21 MB
- Stars: 46
- Watchers: 2
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-list - react-easy-ssr - saga, Styled-components, React-jss, Split code, Server Side Rendering. | tomtom94 | 23 | (TypeScript)
README
# âš› Ultra fast React boilerplate App (with SSR)
Hello, thanks to give me a star for this project.
## Introduction
React App with SSR Server Side Rendering. Webpack 5 installed manually. In dev mode we use live reload thanks to `webpack-dev-middleware` & `webpack-hot-middleware` modules.
Main modules used are `redux-saga`, `loadable-component`, `react-refresh`, `react-jss` and `typescript`.
[Free and easy to use CI/CD](#Continuous-Integration-and-Continuous-Delivery) with Github Actions and Scaleway.
Check out this app in live [reacteasyssrjckf9fbl-reacteasyssrfront.functions.fnc.fr-par.scw.cloud](https://reacteasyssrjckf9fbl-reacteasyssrfront.functions.fnc.fr-par.scw.cloud)
## Table of contents
- [Motivations](#motivations)
- [Getting started](#getting-started)
- [Requirements](#requirements)
- [Start in dev mode](#start-in-dev-mode)
- [Start in production mode](#start-in-production-mode)
- [With Node.js](#with-nodejs)
- [With Docker](#with-docker)
- [Must know about the app](#must-know-about-the-app)
- [Continuous Integration and Continuous Delivery](#continuous-integration-and-continuous-delivery)
- [Checks to do sometimes](#checks-to-do-sometimes)
- [Components](#components)
- [Data-fetching and SSR](#data-fetching-and-ssr)
- [ES6 Imports possible in JSX](#es6-imports-possible-in-jsx)
- [Notes](#notes)## Motivations
All this project is turned about SSR Server Side Rendering. And this is not an easy task. This boilerplate repository allows to overcome this work.
## Getting started
Clone the repo
```git
git clone https://github.com/tomtom94/react-easy-ssr.git
``````git
cd react-easy-ssr
```### Requirements
Node.js version v16.3.0 minimum (because we need to use the [js optional chaining operator](https://node.green/#ES2020)). Hopefully you got `nvm` command already installed (best way to install node), hence just do
```nvm
nvm use
```it's gonna use the `.nvmrc` file with v16.20.0
### Start in dev mode
Get prepared with the env vars
```sh
cp .env-development .env
``````npm
npm install
```Run dev mode with
```npm
npm run dev
```it's gonna start an hot dev middleware with an express server ;) ready to work `http://localhost:3000`
### Start in production mode
#### With Node.js
```npm
npm install
```Write in your server provider the environment variables `BACKEND_BASE_URL`
Run build mode with
```npm
npm run build
```it's gonna build in `dist/`
Then run in production mode
```npm
npm run start
```;) it's gonna start the only one SSR express server out of the box for internet `http://localhost:3000` or environment port used.
#### With Docker
```docker
docker build -t react-easy-ssr .
``````docker
docker run -p 80:80 react-easy-ssr
```Then open `http://localhost:80`
## Must know about the app
You better use a good search engine like [Qwant.com](https://qwant.com), don't use Google. please.
### Continuous Integration and Continuous Delivery
When pushing or merging on master branch, you can trigger Github Actions with a commit message that includes `#major`, `#minor` or `#patch`.
Example of commit message in order to start a deployment :
```git
git commit -m "#major this is a big commit"
``````git
git commit -m "#minor this is a medium commit"
``````git
git commit -m "#patch this is a tiny commit"
```### Checks to do sometimes
- Check typescript `npm run tsc`
- Check eslint `npm run lint`
- Check prettier `npm run prettier`### Components
The main rule is we don't use a frontend framework. All components come from wherever we need it, but we are not stick to one. No need of `material-ui`, no need of `bootstrap` etc... However we are used to copy past source code from them. For example we made a copy past of the wonderfull `material-ui` `` which is so much powerful [check it out in this repo](https://github.com/tomtom94/react-easy-ssr/blob/master/src/components/Grid.tsx). We don't use many components that generate their own css stylesheet, because we need to control this carefully in order to make the famous SSR.
`style-components` and `fontawesome` modules are also installed if ever you wanna use it. And yes we care of them for the SSR also.
Please note we don't use classical CSS style. We use [JSS](https://cssinjs.org/react-jss) (it means js in css). `material-ui` module also uses `react-jss` this is why we didn't installed `material-ui` else it would be stupid to generate twice the `react-jss` stylesheet on the SSR, and inefficiente to make an ultra fast App.
Either you install `material-ui` and you make all your css components with it (which is recommended if you do this for big company), or you get free and install `react-jss` like we did.
### Data-fetching and SSR
Let's see how we fetch our data to feed our redux store. You can find this code in the `` [component](https://github.com/tomtom94/react-easy-ssr/blob/master/src/views/Movies/index.tsx).
```react
const willMount = useRef(true)
if (willMount.current && !process.env.BROWSER) {
dispatch(triggerMovies('GET_MOVIES'))
willMount.current = false
}useEffect(() => {
dispatch(triggerMovies('GET_MOVIES'))
return () => {
dispatch(clearMovies())
}
}, [dispatch])
```- 1st part is only for server side, we dispatch the redux action : with `useRef` you can be sure the action won't be triggered multiple times in an infinite loop.
- 2nd part is only for client side, we dispatch the redux action : but when you trigger this action there is a [redux-saga selector](https://github.com/tomtom94/react-easy-ssr/blob/master/src/store/reducers/selectors.ts) which will check if data hasn't been already fetched during 1st part, if yes no need to fetch again. And we clear the error if there are some before leaving the component.This way your App is able to fetch data on the server & client side independantly.
### ES6 Imports possible in JSX
Webpack setup only allows us to import files with ES6 in type
- .js .jsx .ts .tsx
- .png .jpe .jpeg .gif .ico
- .woff .woff2
- .css (remember `react-jss` generates its own stylesheet via its own plugins, not via webpack loaders)You can add more Webpack `loader` to your project...
## Notes
If ever you wanna brainstorm, download my resume you are gonna find my phone number
- [thomasdeveloper-react.com](https://www.thomasdeveloper-react.com)