create-react-app: Change src of bundle.js in development

Viewed 3081

I'm trying to change the src of bundle.js in development with create-react-app.

By default the path is: /static/js/bundle.js

<body>
<div id="root"></div>
</script><script type="text/javascript" src="/static/js/bundle.js"></script></body>

In our production we use Apache as proxy to our API, to test SSO and other functionalities. So I have to add some string to the path, to be like this: myApp/static/js/bundle.js

<body>
<div id="root"></div>
</script><script type="text/javascript" src="myApp/static/js/bundle.js"></script></body>

I tried homepage in package.json, but it only works in npm run build. It also isn't proxy settings, not HOSt in .env

Is this even possible with create-react-app? I checked documentation but didn't find any solution.

2 Answers

you will have to 'npm run eject' and modify the webpack files to change the output.

Little late but if this helps others, this is how you achieve it. After eject, take a look in the config folder, the file: webpack.config.dev.js:

const publicPath = '/';
// `publicUrl` is just like `publicPath`, but we will provide it to our app
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
const publicUrl = '';

There you could change this values or, second option is to create a .env file and add:

PUBLIC_URL=/xxx
Related