5

I am using create-react-app and running react-scripts build on a my project, but I'm having an issue with the build output. I need the build output to go in a subdirectory of the build folder like shown here

Build
-- Player 

And I need the Urls for the generated for the JS and CSS files as shown here to include the Player in the path. I need these.

<link href="/static/css/main.02096f02.css" rel="stylesheet">
<script type="text/javascript" src="/static/js/main.75412701.js"></script>

to be these

<link href="/player/static/css/main.02096f02.css" rel="stylesheet">
<script type="text/javascript" src="/player/static/js/main.75412701.js"></script>

I need this to automate my build and deployment. Otherwise the default scripts work perfectly.

Danny Ellis Jr.
  • 1,674
  • 2
  • 23
  • 38

2 Answers2

5

If you set the homepage attribute in your package.json file, that will modify all the links generated in /build/index.html. Here's the docs.

"homepage": "http://mywebsite.com/relativepath",
carpiediem
  • 1,918
  • 22
  • 41
1

You can add postbuild script in package.json

"scripts": {
    "build": "react-scripts build",
    "postbuild" : "mv build /Player/"
}

Please try this.

Midhun G S
  • 906
  • 9
  • 22
  • 1
    The question is about a sub-directory on the web server, not the location of the files on your local computer. – carpiediem Dec 12 '19 at 05:19