I'm trying to implement conditional compilation. I use the EnvironmentPlugin to achieve this. https://webpack.js.org/plugins/environment-plugin/#root The goal is to make webpack remove unused code from the final bundle.
The following works. calculation() is not being called and therefore it is not included.
if(process.env.MY_VARIABLE === 'some_value') {
calculation()
}
But this does not:
const check = process.env.MY_VARIABLE === 'some_value'
if(check) {
calculation()
}
Is there a way to make webpack think harder? check is a const variable, the value can't be changed to something different. So this should work.
I'm still using webpack 4. Is it possible this might work in webpack 5?