Skip to content

Instantly share code, notes, and snippets.

@ScriptedAlchemy
Last active November 25, 2019 00:47
Show Gist options
  • Select an option

  • Save ScriptedAlchemy/4eb543aca9a5777c3957006fe23fb055 to your computer and use it in GitHub Desktop.

Select an option

Save ScriptedAlchemy/4eb543aca9a5777c3957006fe23fb055 to your computer and use it in GitHub Desktop.
Export used in unknown ways
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