liady / webpack-node-externals

Easily exclude node modules in Webpack
MIT License
1.3k stars 62 forks source link

Adding a debug mode #117

Open DannyvanderJagt opened 2 years ago

DannyvanderJagt commented 2 years ago

While using this externals package I ran into an issue where packages weren't bundled that were suppose too. It turned out to be a mistake by me, but it was far from obvious.

A use case to illustrate:

We are using the package accessible-autocomplete but in the code it's actually imported as accessible-autocomplete/preact. When I added "accessible-autocomplete" to the allowlist it didn't include it in the bundle. After a bit too many hours, I ended up debugging this package and found the problem.

Debug mode

It would be nice to add a debug mode to this package that will output exactly which packages were included and excluded from the bundle.

It could output a simple for formatted list like this:

Included packages: [ ..... , ..... ]
Excluded packages: [ ..... , ..... ]

Or an detailed list of the internal results from these two checks:

 utils.contains(nodeModules, moduleName) &&
 !utils.containsPattern(allowlist, request)

See here. They include regex and string comparison checks that will easily fail on typos or a slightly different naming like the use case above.

What do the contributors think? I'm happy to create a PR and propose something.