danieldelcore / trousers

hooks-first CSS-in-JS library, focused on semantics and runtime performance
https://danieldelcore.github.io/trousers/
MIT License
302 stars 6 forks source link

Build-time optimisations via Bable-macros #67

Open danieldelcore opened 4 years ago

danieldelcore commented 4 years ago

We should look into this as a way to reduce runtime costs! And set us up for zero-config SSR:

https://babeljs.io/blog/2017/09/11/zero-config-with-babel-macros

so using the babel macro we could go from this:

/** @jsx jsx */
import { css, jsx} from '@trousers/core'

const styles = css`
  color: white;
`;

const Button = props => {
    const classNames = useStyles(styles, props);

    return <button className={buttonClassNames}>{props.children}</button>;
};

export default Button;

to this:

/** @jsx jsx */
import { css, jsx} from '@trousers/macro'

const styles = css`
  color: white;
`;

const Button = props => {
    return <button css={styles}>{props.children}</button>;
};

export default Button;