-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Description
Bug report
***EDIT: I originally wrote that this issue was due to "barrel files" but as I was creating the repro case, I realized that isn't true. Pure barrel files seem to work. I've refined the issue description below.
What is the current behavior?
If there is a module that imports/exports another module without explicitly referencing any of the exports of that module, webpack disables export mangling for the module.
In a large code base, this creates a significant code bloat because all of the references everywhere to the exports of the modules will use the full name instead of a mangled one or two characters. This really adds up.
If the current behavior is a bug, please provide the steps to reproduce.
A simple repro case for this can be found here, with a description in the README: https://github.com/scameron/webpack-issue-mangling
What is the expected behavior?
Ideally, the export mangling would continue to be enabled even if I have modules that do not explicitly reference the exports but just "pass-through" the imports as subsequent exports. I can't think of any reason why this case would need to disable export mangling, but maybe I'm missing something.
I took a quick look at the code, but I'm not sure this is correct. Here's what I found though:
In the FlagDependencyUsagePlugin, where it analysis dependencies between modules and determines whether or not export mangling should be used or not used, it has a check to see if the usedExports array is empty, meaning that the module being processed does explicitly use any of the exports of the dependency module being considered. If this is true, it will call SetUsedInUnknownWay on the export info, which internally sets canMangleUse to false.
For reference:
- The
FlagDependencyUsagePlugincode that checks for empty "used exports" during dependency processing is here: FlagDependencyUsagePlugin.processReferencedModule - The
ExportInfocode that setscanMangleUseto false is here: ExportsInfo.setUsedInUnknownWay