create-react-app build deploy on LAMP/XAMPP/WAMP

前端 未结 4 1510
星月不相逢
星月不相逢 2020-12-16 02:36

How to deploy the build on Apache WAMP/XAMPP server?

I have an app created with create-react-app and I have two pages on this applicati

4条回答
  •  渐次进展
    2020-12-16 03:20

    Create a folder in htdocs (xampp) named react.

    add "homepage": "./", (for relative path) or "homepage": "http://localhost/react/", (absolute path) in package.json file.

    And on App.js file

    
      
        
          Hello
        
         "404 Not found!"} />
      
    
    

    After configuring package.json and App.js run build command

    npm run build
    

    Then copy all files from build folder to react folder in htdocs.

    And also create an .htaccess in react folder in htdocs.

    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.html [QSA,L]
    

    If your sub folder name is different then replace /react with your folder name.

    Example - rename /react from

    "homepage": "http://localhost/react/"  
    
    

    to

    "homepage": "http://localhost/your_folder_name/"
    
    

提交回复
热议问题