Replies: 3 comments 1 reply
-
For posterity: Here's a brief explanation https://youtu.be/SeVF1OFy5_I?t=929 |
Beta Was this translation helpful? Give feedback.
0 replies
-
But I don't understand what the first argument is |
Beta Was this translation helpful? Give feedback.
0 replies
-
Ok, I get it now: addFunctionSerializer adds the metadata VE needs to import the function once compiled, and the first argument is the same result you want to have once compiled. For example, this allows you to do import { style, CSSProperties } from '@vanilla-extract/css';
import { addFunctionSerializer } from '@vanilla-extract/css/functionSerializer';
import { styled as realStyled } from './styled';
type StyledProxy = {
[tag: string]: (css: CSSProperties) => ReturnType<typeof realStyled>;
};
export const styled: StyledProxy = new Proxy(
{},
{
get(_this, tag) {
return (css: CSSProperties) => {
const className = style(css);
const Lite = realStyled(tag, className);
// This tells VE how to recreate Lite in the compiled CSS
addFunctionSerializer(Lite, {
importPath: './styled',
importName: 'styled',
// @ts-ignore
args: [tag, className],
});
return Lite;
};
},
}
); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
See title :-) How to use addFunctionSerializer?
Beta Was this translation helpful? Give feedback.
All reactions