-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Output tree-shakeable friendly classes when compiling ES5 #182
Comments
It's also possible that the fix for this is in the rollup-plugin-terser side or on terser to consider |
This looks like something a separate plugin should do, either rollup plugin like you had, or a typescript transformer. I'd rather not modify typescript output for everybody, too many possible unintended consequences. |
That makes sense, let me follow up with the terser repository as it may have broader impacts than just rollup |
I'm going to close this, seems most suggestions is to use a transformer as I already was. Looks like babel also has a transformer to add the PURE script into it's ES5 output. Sorry for the noise! |
Any update on how you got around this @k2snowman69 ? |
Sigh, I hate replying when I know people are going to thumbs down it. Here are the changes I made to get this to work:
Again, not the answer a rollup repository is going to want to hear, however it did remove a ton of dependencies and complications for me which actually made maintenance easier. |
What happens and why it is wrong
I've been investigating why one of my React Typescript component libraries doesn't treeshake nicely. An important fact is that I'm outputting ES5 target.
The cause I've come down to is because terser works best with es2015 modules and defaults to a more safe output. Since ES5 doesn't have import/export type situations it's hard terser to know what is safe to strip out. However with typescript I think there is a solution and I ran into it here specifically this custom plugin:
When typescript compiles, it adds a
/** @class */
comment in front of every class object it transpiles. Simply replacing this class comment with Terser's__PURE__
comment allows Terser to know it can tree shake these objects.I further checked to make sure if prop-types is being used it wont remove the function. For example the following would be tree-shaked
but the following would not due to it having possible unintended consequences
So the ask here is that rollup-plugin-typescript2 does the replacement of
/** @class */
to/*@__PURE__*/
so that the ES5 outputs would be tree-shaken down stream.Environment
N/A
Versions
rollup.config.js
tsconfig.json
package.json
Only relevant part is my build script
plugin output with verbosity 3
N/A
The text was updated successfully, but these errors were encountered: