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
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With