reactjscreate-react-appreact-scripts

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?


Solution

  • 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;