How to deploy a React App on Apache web server

后端 未结 8 2158
谎友^
谎友^ 2020-11-29 18:11

I have created a basic React App from https://www.tutorialspoint.com/reactjs/reactjs_jsx.htm here , I want to run this test code on Apache based server, I know that I need t

8条回答
  •  臣服心动
    2020-11-29 18:56

    Before making the npm build,
    1) Go to your React project root folder and open package.json.
    2) Add "homepage" attribute to package.json

    • if you want to provide absolute path

      "homepage": "http://hostName.com/appLocation",
      "name": "react-app",
      "version": "1.1.0",
      
    • if you want to provide relative path

      "homepage": "./",
      "name": "react-app",
      

      Using relative path method may warn a syntax validation error in your IDE. But the build is made without any errors during compilation.

    3) Save the package.json , and in terminal run npm run-script build
    4) Copy the contents of build/ folder to your server directory.

    PS: It is easy to use relative path method if you want to change the build file location in your server frequently.

提交回复
热议问题