'react-scripts build generates wrong path for sub folder

My application should be served at /sub-folder so in the package.json the homepage field is set to

"homepage": "/sub-folder/",

The production bundle generated by react-scripts build is placed inside the dist directory that looks like

/dist
  /static
    /js
      main.[hash].js
      ...
    asset-manifest.json
    index.html
    ...

However index.html is trying to load at the following path

<script defer="defer" src="/sub-folder/static/js/main.41ee4874.js">

and obviously fails and won't load anything.

What is wrong with my configuration?



Solution 1:[1]

I hope you are looking for it.

/ package.json
  "scripts": {
    "build": "BUILD_PATH='./sub-folder' react-scripts build",
    // ...
  },

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sujeet Mishra