-
Editing this post. I found some documentation about named CSS var in the blog (forgot to look there). First off, thanks for all the feedback in these discussions. I have some questions about using named variables, as well as patterns on how to import them and performance (tree shaking). By switching to named CSS variables (using Does StyleX do tree shaking for Because some tokens pull from other defined tokens, I have to make separate export const colors = defineVars({
'--s-color-peri-50': "#63f10a",
});
export const colorsSymantic = defineVars({
'--primary': colors2['--s-color-peri-50'],
}); Because I have many functions in one // defined in colors.stylex.js
export const colors2 = defineVars({
'--s-color-peri-50': "#63f10a",
});
export const colorsSymantic2 = defineVars({
'--primary': colors2['--s-color-peri-50'],
});
export const allColors = {
...colors2,
...colorsSymantic2,
};
// defined in colors.stylex.d.ts
type TColors = Readonly<{
peri_50: string;
}>;
type TSemanticColors = Readonly<{
primary: string;
}>;
type TAllColors = TColors2 & TColorsSymantic2;
export declare const colors: VarGroup<TColors>;
export declare const symanticColors: VarGroup<TSymanticColors>;
export declare const allColors: VarGroup<TAllColors>;
// Usage
import { allColors as $ } from '@acme/tokens/colors.stylex';
const styles = stylex.create({
base: {
backgroundColor: $["--s-color-peri-50"],
color: $["--primary"],
}
}); Do you see any drawbacks from using this pattern? Is using the Thanks again! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
updated the original post, finding the blog post cleared up a lot of questions. |
Beta Was this translation helpful? Give feedback.
-
It looks like what happens is that all the variables are attached to |
Beta Was this translation helpful? Give feedback.
-
Yes.
Not yet. But you probably run the output CSS file through a postcss plugin to strip out unused variables.
You're breaking the rules of variables. Don't do that. Put all the variables within a single Something like this should work though: // defined in colors.stylex.js
export const colors2 = {
'--s-color-peri-50': "#63f10a",
};
export const colorsSymantic2 = {
'--primary': colors2['--s-color-peri-50'],
};
export const allColors = defineVars({
...colors2,
...colorsSymantic2,
}); |
Beta Was this translation helpful? Give feedback.
Yes.
Not yet. But you probably run the output CSS file through a postcss plugin to strip out unused variables.
You're breaking the rules of variables. Don't do that. Put all the variables within a single
defineVars
if you want that convenience. Don't try to "re-export" variables. That's not supported.Even with the
--
variable names, things may work right now, but it's not a supported pattern and could break with a future update.Somethi…