-
Hi all! I must be missing something here. But how can I use StyleX for components in a distributed design library, in a NPM package? Currently we have a bunch of components that gets compiled and distributed using emotion CSS but if StyleX generate ONE css file how would that work? I don't want consumers of the package to have to use that complete file when only using a component or two. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
The process works exactly how
So, don't worry, the consumers will only pay for what they use. And if they're using StyleX for their own projects, the costs for all the common CSS will be shared. Some things to remember:
|
Beta Was this translation helpful? Give feedback.
-
Does it also work with Next.js? Is there any special considerations to make that works? In short, my package (built with rollup) exports this: import React from 'react';
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
container: { border: '2px solid red' },
});
export const Test: React.FC = () => <div {...stylex.props(styles.container)}>Test</div>; In the consumer (Next.js) app with stylex set up, I use it like this: import React from 'react';
import { Test } from '@my/design-system';
const TestDemo: React.FC = () => <Test />;
export default TestDemo; Everything else is styled, but the Test component is not styled. Edit: I thought that the npm package should not pre-compile stylex, and let that work to the consumer app. But this led to |
Beta Was this translation helpful? Give feedback.
The process works exactly how
@stylexjs/open-props
works in the NextJS example. Here's the TLDR;node_modules
that uses StyleX and extract the relevant CSS.So, don't worry, the consumers will only pay for what they use. And if they're using StyleX for their own projects, the costs for all the common CSS will be shared.
Some things to remember:
Autoprefixr
on the generated CSS file if you…