How to bundle a React app to a subdirectory on a server?

前端 未结 10 2172
名媛妹妹
名媛妹妹 2020-12-04 14:41

I have a React app I\'ve been developing on my localhost. I want to copy it to a server into a subdirectory called vensa.

My webpack config file looks like this..

10条回答
  •  孤街浪徒
    2020-12-04 15:24

    1. Add "homepage": "https://yourdomain/subdirectory/" in package.json
    2. Update the Routes, set sub directory in route,
    
      
    
    
    1. Add base in public/index.html. It helps to set path without issues.

    2. make all css, js, images & all resource loading './assets/your resource.'

    3. Only look if you are using history. add basename in history

        const historyConfig = {
            basename: 'your subdirectory'
        };
        const history = createBrowserHistory(historyConfig);
    

提交回复
热议问题