reactjsreact-routergeneralization

How to deploy js in production?


I am React js beginner so I wanted to clarify some things.

Q1. The only way to use React in production is to use webpack-dev-serve ?

Q2. In case that you use webpack-dev-server I should create multiple API which will handle multiple functionalities as another service or microservice ?

Q3. Should you learn node js for further development ? Or it's enough to have knowledge in webpack ?

Thank you in advance!


Solution

  • The answer to 1. is no, it's not meant to serve production code.

    The answer to 2 and 3: there are many ways to deploy a React app, and the right answer for you is..... it depends. Some of those don't require you to learn node (or anything to set up a server). The React docs actually provide a lot of the ways to start: https://facebook.github.io/create-react-app/docs/deployment#github-pages-https-pagesgithubcom

    If you have an lightweight page, I would recommend something like Github pages or comparable: https://github.com/gitname/react-gh-pages

    For reference, here's a React project I built for a coding interview: https://github.com/pink-cupcakes/connect-four

    And here is the deployed site via Github pages: https://pink-cupcakes.github.io/connect-four/

    But if you deploy a project with a compiled bundle.js, you can actually just open your index.html and it'll run all of your React goodness. Then your question just becomes - how do you deploy a server, and there are many options for that: Heroku, Azure/AWS.

    If that sounds like a headache - take a gander at serverless! (Devops magic - automated) https://dev.to/adnanrahic/a-crash-course-on-serverless-side-rendering-with-reactjs-nextjs-and-aws-lambda-13ed