Git Product home page Git Product logo

tomtom94 / react-easy-ssr Goto Github PK

View Code? Open in Web Editor NEW
47.0 2.0 6.0 3.29 MB

๐Ÿ”ฅ React Starter Project with Webpack 5, Babel 7, TypeScript, Redux-saga, Styled-components, React-jss, Split code, Server Side Rendering.

Home Page: https://reacteasyssrjckf9fbl-reacteasyssrfront.functions.fnc.fr-par.scw.cloud

License: MIT License

JavaScript 14.09% Dockerfile 0.33% TypeScript 77.87% HTML 7.29% CSS 0.44%
react typescript ssr redux-saga loadable-components babel7 styled-components react-jss webpack5

react-easy-ssr's Introduction

โš› Ultra fast React boilerplate App (with SSR)

react webpack babel jss jss jss

star github 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.

star github Free and easy to use CI/CD with Github Actions and Scaleway.

Check out this app in live reacteasyssrjckf9fbl-reacteasyssrfront.functions.fnc.fr-par.scw.cloud

Table of contents

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 clone https://github.com/tomtom94/react-easy-ssr.git
cd react-easy-ssr

Requirements

Node.js version v16.3.0 minimum (because we need to use the js optional chaining operator). Hopefully you got nvm command already installed (best way to install node), hence just do

nvm use

it's gonna use the .nvmrc file with v16.20.0

Start in dev mode

Get prepared with the env vars

cp .env-development .env
npm install

Run dev mode with

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 install

Write in your server provider the environment variables BACKEND_BASE_URL

Run build mode with

npm run build

it's gonna build in dist/

Then run in production mode

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 build -t react-easy-ssr .
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, 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 commit -m "#major this is a big commit"
git commit -m "#minor this is a medium commit"
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 <Grid /> which is so much powerful check it out in this repo. 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 (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 <Movies /> component.

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 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

react-easy-ssr's People

Contributors

dependabot[bot] avatar petitfilou666 avatar tomtom94 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

Watchers

 avatar  avatar

react-easy-ssr's Issues

Setup a free PRODUCTION github CI to create & serve docker container's static files via Nginx

Is your feature request related to a problem? Please describe.
Yes in production mode there is just a code comment how you can manage static files, but there isn't nothing more

Describe the solution you'd like
All is in the title : setup a free PRODUCTION github CI to create & serve docker container's static files via Nginx

Describe alternatives you've considered
We are gonna put these docker containers into a free heroku account

Additional context
You are gonna enjoy a fat CI/CD, by just commiting with a special code, it's gonna deploy in production or no

connected-react-router module uninstall

In order to migrate to react 18, we need to remove connected-react-router which is not maintained anymore. The module react-router-dom nowadays offers us enought hooks like useLocation, useNavigation...

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.