Last active
November 25, 2019 00:47
-
-
Save ScriptedAlchemy/4eb543aca9a5777c3957006fe23fb055 to your computer and use it in GitHub Desktop.
Export used in unknown ways
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| compiler.hooks.thisCompilation.tap( | |
| "FlagEntryExportAsUsedPlugin", | |
| compilation => { | |
| const moduleGraph = compilation.moduleGraph; | |
| compilation.hooks.seal.tap("FlagEntryExportAsUsedPlugin", () => { | |
| for (const deps of compilation.entryDependencies.values()) { | |
| for (const dep of deps) { | |
| const module = moduleGraph.getModule(dep); | |
| if (module) { | |
| const exportsInfo = moduleGraph.getExportsInfo(module); | |
| if (this.nsObjectUsed) { | |
| // mark that exports are used in an unknown way, preventing tree-shaking on a file or module | |
| exportsInfo.setUsedInUnknownWay(); | |
| } else { | |
| exportsInfo.setAllKnownExportsUsed(); | |
| } | |
| moduleGraph.addExtraReason(module, this.explanation); | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment