'Does webpack evaluate and remove unreachable code inside a function?
I have a function like this
function webpackTest(){
if(1==0)
{
console.log("MyConsoleLog");
}
}
function doThings() {
// Before test things
webpackTest()
// After test things
}
It seems like that my build output does not even include the string "MyConsoleLog" anywhere
My question is that does/can webpack evaluate code and remove "dead code", even intentionally inside a function
And if there is away to disable that, specifically
Solution 1:[1]
I got the answer. The built code removal was the work of Terser webpack plugin https://www.npmjs.com/package/terser-webpack-plugin
If you face the same situation that I faced, check the Webpack plugin configuration, the section for Terser. The config section that govern code removal is compression such as conditionals, dead_code, evaluate
https://github.com/terser/terser#compress-options
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | qkhanhpro |
