How to override a behavior of __webpack_require__ function?

I encountered a problem with my project. For sharing modules, I use the require() function, which, as I know, evaluates the entire code of the module and encapsulates it in another function. However, I would like to reduce the amount of code that is evaluated in order to not include components if they are not used in the template.

For example, I have components Page, Button1, Button2. The Page component has 2 dependencies: Button1 and Button2, but only Button1 is used in the template of the Page component. Therefore, I would like not to include the dependency Button2 in the Page component.

I’d like to change the logic of function webpack_require for cancel component code evaluation if this component isn’t used.

I used DefinePlguin and ProvidePlugin of webpack for overriding the webpack_require function, but it didn’t work 🙁