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

前端 未结 10 2118
名媛妹妹
名媛妹妹 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:26

    In my situation, I needed to support a scenario, where there might be 0 to many subfolders with unknown names and production uses only static files.

    In my App.js, I defined this simple function:

    const getBasename = path => path.substr(0, path.lastIndexOf('/'));
    

    Which I use to define the basename:

    
    

    This works with no subfolder as well as many subfolders and it can manage reloads as well.

提交回复
热议问题