I'm using React Router inside Create React App to handle my apps navigation. Along with my pages, I also have a route used only for development to display styles (/styles). I'd like to exclude this route when the build command runs so it's removed in production.
I'm currently thinking of checking an environment variable but is there a better way?
You can use the process variable for that.
If you wrap that router with process.env.NODE_ENV === 'development', this will become false during building and this route will be excluded, since process.env.NODE_ENV is production and static false statements will be removed.
{process.env.NODE_ENV === 'development' && <Route ... />}
You can read more about it here.
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