create react app Configuration file after build app

Hamid Sarani picture Hamid Sarani · May 16, 2018 · Viewed 8.1k times · Source

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?

Answer

Midhun G S picture Midhun G S · May 16, 2018

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;