feat(generator): export tokens individually (WIP) #3300
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.
📝 Description
Export tokens individually for tree shaking (+30kb savings).
⛳️ Current behavior (updates)
All tokens are exported in one single object.
🚀 New behavior
Tokens are still exported in a single object, but a new variable (
tokens
) is available to store all the individually exported tokens.💣 Is this a breaking change (Yes/No):
No.
📝 Additional Information
There are some issues to address due to the character limit on JS variable names. This has been resolved as follows.
If the variable name is valid, the token can be accessed directly:
If the variable name is invalid, it will be accessed via a map (e.g.,
tokens.$['sizes.special_Name!']
).To maintain a similarity with tokens, an exception has been made so that negative numbers cannot be exported in variables:
spacing.-1
will be converted tospacing_n1
.There are still some tokens with names that are not allowed due to the use of the (
-
) character (panda/packages/studio/styled-system/tokens/tokens-entry.mjs
Line 478 in 0519505
easings.in-out
sizes.breakpoint-sm
sizes.breakpoint-md
sizes.breakpoint-lg
sizes.breakpoint-xl
sizes.breakpoint-2xl
You can always transform
-
into_
to allow it to be exported, but this causes conflicts (e.g.,easings.in_out
andeasings.in-out
would use the same name).Another solution for later is to limit the characters allowed in the tokens.