react-app-rewire-ifdef
Adds ifdef-loader to a react-app-rewired config, which allows JavaScript or TypeScript conditional compilation with preprocessed statements like #if
, #elif
, etc.
Installation
yarn add --dev react-app-rewire-ifdef
Example
config-overrides.js
:
const rewireIfdef = moduleexports =
I added one option that is not in ifdef-loader
: "ifdef-env"
which, when set to true
, automatically loads all environment variables into the loader. For example :
const rewireIfdef = moduleexports =
Then in your app code :
/// #if NODE_ENV === 'production'console/// #endif