react exclude config files from build

I don’t know why this works but I did it like this:

if(process.env.REACT_APP_NODE_ENV==="prod"){
    var config=require("../config_prod.json")
}
if(process.env.REACT_APP_NODE_ENV==="dev"){
    var config=require("../config_dev.json")
}
if(process.env.REACT_APP_NODE_ENV==="test"){
    var config=require("../config_test.json")
}
else if(process.env.REACT_APP_NODE_ENV==="staging"){
    var config=require("../config_staging.json")
}




export default config;

this way any unused config file won’t end up in the production bundle. This only works if process.env is in the if clause, if it is for example Math.random()<0.5, it will bundle everything

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top