This POC explore whether or not a library compiled with tsup is tree-shakeable if the treeshake
option is not explicitly set to true
. The tsup documentation doesn't say much about the matter and this issue is particularly confusing.
After testing with a super simply library, it turns out that a library is tree-shakeable even if the treeshake
option is not set to true
.
What really matters is that the splitting
option is true
, allowing sideEffects
optimization and to also include the Terser plugin.
Still, as explained in this article, unused imports might not be cleaned up since webpack do it's tree shaking before terser is executed. Therefore, if imports becomes useless after terser eliminated dead code, the import will still be included in the final bundle.