I want a Config File (JSON) in root folder after build to config my app.
like Translation
and API Urls
and ...
Can I do this with create react app?
Create config.js
or json
file outside src
directory and include it in index.html
like
<script src="%PUBLIC_URL%/config.js" type="text/javascript"></script>
configure parameters in config.js
var BASE_URL = "http://YOUR-URL";
you can get paramenters like
const BASE_URL = window.BASE_URL;
You can store you JSON file in the public/
folder and it'll automatically provide this file when you host your Create React App.
Something like: /public/my-configuration-file.json
then when you restart your application:
localhost:3000/my-configuration-file.json
will provide you this json file.
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