I have recently switched from using .env file to a secrets management tool, Doppler, and is trying to inject the variables from Doppler into React, which is built by webpack.
However, simply by running
doppler run -- webpack serve --config webpack.dev.js
does not do the trick. What should I do if I want to inject env from Doppler into webpack to build my React app?
I found out about the
EnvironmentPlugininwebpack,When you run
doppler run -- webpack serve --config webpack.dev.js, doppler injected the env variables into the runtime and we can pass them withEnvironmentPluginby specifying the key name in the array and pass that into the pluginAnother approach is to pass an object instead, and this approach allows for default values in case doppler has failed to provide the key
As long as the key specified in either the array or the object matches that in doppler, this should work.
referencing webpack docs here