Thank you for the article. I have gone through all these problems and finally reached a solution that works.
You have mentioned the use of UglifyJS and maybe that is a problem because it removes helpful comments for the webpack to remove the unused code. Shouldn’t you have not used UglifyJS and let webpack4 do minification for you have done the tree-shaking? Also, I don’t understand why you need rollup to transform libraries to tree-shakable output with imports and exports and rest converted to es5. I use typescript configured to target es6, module es6, and module type to “node” and generate a similar output as Rollup.
There is a plugin called Deep Scope Analysis for the webpack that does further tree-shaking, but unfortunately, it didn’t work for me due to some errors.