webpack indiscriminately bundling files that are not used

I have a React app that imports a library.

In the imported library, there is a function, foo, that has this line of code:

require(`./folder/${file_name}`)

The problem is, this function foo is never called and will never be called.

Yet, all of the files inside of ./folder is bundled anyways, which needlessly increases the bundle size.

How can I get webpack to not bundle the files in this folder?