Tuesday, November 7, 2017

Webpack - Determine why a file is included

Leave a Comment

I have a webpack config with some loaders and plugins. These loaders have some include/test/exclude rules.

However, a set of files keep being included in the webpack build. They're not imported anywhere which means it's likely some bad config.

Is there a way to ask webpack WHY a file is included in a build?

2 Answers

Answers 1

There are some Display Options you can set when running webpack that can help you with what you want to achieve. Check them here.

There is a specific one, --display-reasons that will show the reasons why a module is included, or at least more information about why it is included. Also this one: --display-modules may be interesting to show modules that are hidden from the output by default because they come from directories like node_modules or bower_components.

I hope this helps.

Answers 2

Without knowing more about what set of files are being included, I'd suggest setting:

stats: 'verbose' 

in your webpack config. Depending on the size of your app, this may dump a lot of info, but it should display where a given file or files is/are being included from. The stats config object can also be tailored to display more specific info.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment