Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create react app Configuration file after build app

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?

like image 625
Hamid Sarani Avatar asked May 16 '18 11:05

Hamid Sarani


2 Answers

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

config.js

var BASE_URL = "http://YOUR-URL";

you can get paramenters like

const BASE_URL = window.BASE_URL;
like image 199
Midhun G S Avatar answered Oct 18 '22 19:10

Midhun G S


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.

like image 35
Tanato Avatar answered Oct 18 '22 20:10

Tanato