Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-scripts build a file into `build` folder, from a different folder than `public`

I have a react app. In my package.json:

"build": "react-scripts build",

After running this build script:

npm run build

Everything is built into the build folder and any files from the public folder get copied to the root of the build folder as they are (not minified into chunks). So any static files I want copied over and not changed I can put into the public folder.

I want to copy a file over as if it were in the public folder, but from a different folder such as /src/files/config.js

What's the best way to do that? Is it something like adding a webpack.config.js to the root of my app and having a custom configuration for sending over a file like this? Or maybe just a quick modification to the npm script in package.json somehow? Or am I missing something...

Thanks

like image 743
StefanBob Avatar asked Oct 20 '25 05:10

StefanBob


1 Answers

Without ejecting or getting overly complex, set your scripts to something:

  "build": "react-scripts build && cp /src/files/config.js build"

Might be worth pointing out to make sure that cp works in the environments you are supporting.

Windows:

"react-scripts build && copy src\\files\\config.js build"
like image 68
OFRBG Avatar answered Oct 21 '25 18:10

OFRBG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!