Deploying ReactJS application in production (with nodeJS backend)

前端 未结 3 773
清酒与你
清酒与你 2021-02-11 05:28

our project is now over, we only have two weeks to give back the project for our final year\'s studies at University. Our teacher told us that now that development phase was ove

3条回答
  •  Happy的楠姐
    2021-02-11 05:59

    To deploy a react app build with the cli create-react-app , first you need to set the host in your package.json , so in your package.json added this line

    "homepage":"http://localhost/" ,assuming you will host your app on the root directory of your webserver 
    

    your package.json will look something like this

    {
      "name": "nameofyourapp",
      "version": "0.1.0",
      "private": true,
      "homepage":"http://localhost/",
      "dependencies": {
        .....
      },
      "scripts": {
      ......
      }
    }
    

    then inside your app folder run this commande

    npm run build
    

    then copy what inside your build folder and paste it in the root directory of your serveur you will ended up with files like this

    httdocs //root directory of your webserver
      |
      |-static
      |
      |-index.html
      |-serviceworker.js
    

    after that you cant access your webserver from your browser : http://localhost/

提交回复
热议问题