-
Hey! This question(s) is more about the tactics and tips for using Stylex in the monorepo and sharing the tokens with other dependent libraries and products. I'm playing around with stylex in the monorepo setup and currently I was trying to achieve this goal: Create the package with design tokens and share them around few ui packages to build themable ui-kit. So in practice it will look like:
Example component styles that works: // package/b/src/button/button.styles.ts
import { colors } from "../../../package/a/tokens.stylex"
const buttonStyles = stylex.create({
primary: {
color: colors.primary,
}
...
}); In this case it works because I used the relative path to other package which is rather tricky workaround of a problem of sharing the tokens around packages. I want to easily develop different parts of the library or allow other packages (not necessarily in the same repository) to reuse tokens and build their own components or themes for the library. I wanted to ask if you have any idea what this could look like, whether it will be possible to import My thoughts on this mainly focus on the simplicity of installing such a design system from the point of view of the creator of libraries based on Stylex. From my point of view, simply enabling import from a file in the simplest way possible, i.e.: // package/b/src/button/button.styles.ts
import { colors } from "package/a"; // that's not allowed when it's compiled into index.mjs
const buttonStyles = stylex.create({
primary: {
color: colors.primary,
}
...
}); I guess only solution for this would be just keeping the file named index.stylex.ts as the bundle? 🤔 That would be great. However, I'm sure you probably have some way we should proceed when creating such solutions. Therefore, I would like to find out how to best solve this. I intend to use it in planned libraries and it would be great to learn a bit more about the tactics of developing this kind of system and libraries, which can then be used to create other libraries, sharing tokens with creators and therefore theming possibilities they provide. I will be grateful for your answer, thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
When using The current limitations are:
|
Beta Was this translation helpful? Give feedback.
When using
npm
monorepo features, it should "just work". StyleX relies on Node'srequire.resolve
for compilation, so anything that node understands, StyleX understands. You should ensure that therootDir
is the root of the mono-repo and not one of the packages within.The current limitations are:
@/
alias that Typescript and the bundler understands, but Node.js doesn'tpnpm
uses symbolic links for packages so while it works, it's less reliable than any of the other package managers.rootDir
manually.