Open
Conversation
Collaborator
We're already discussing this... |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed / motivation ?
This PR makes a couple changes to improve the treeshakability of the
@stylexjs/stylexpackage.sideEffectsflag tofalsein thepackage.json. Although rare in typical usage this would allow bundlers to remove unused importsfrom '@stylexjs/stylex'. This is also a general best practice if the library has no side effects. I noticed thatstyleqalready has this flag setlegacyMergeinto a IIFE and annotated it with/*@__PURE__*/with a rollup plugin. Even withsideEffect: falseset some bundlers (definitely webpack from my testing) would consider setting a property like_legacyMerge.create =to be a side effect and the code would not be marked for dead code elimination. I tried adding/*@__PURE__*/in the source but it was not being preserved, so I resorted to a rollup plugin. I think there is something I couldn't easily figure out about the flow or hermes-parser plugins that remove comments.With webpack and this change I am seeing a bundle size reduction from
3.4KBto1.4KBfor a simple entry point that only uses thepropsimport (webpack is able to analyze namespace imports in most cases)Questions
legacyMergeor at least the patching of the variables onto it? It seems undocumented?Pre-flight checklist
Contribution Guidelines