Replies: 4 comments
-
The setup can be made to work, but the alias setup for StyleX needs to resolve to absolute file paths. Specifically, in your Vite Config, you'd need something like this: styleX({
aliases: {
'@repo/ui': path.join(fileURLToPath(new URL('./src', import.meta.url)), 'packages/ui')
}
}), When using the theming APIs, StyleX needs to resolve the actual file path where If this doesn't work, please share a repro project so I can help further. Also make sure to try both Vite plugins ( |
Beta Was this translation helpful? Give feedback.
-
It did not work for me, but I created a repo for you to play with :) https://github.com/tilnea/stylex-turbo-demo I know its a weird setup, having react in vue and such, but I thought its best to just make it as close to the real reop as possible, where we are starting to convert parts to react bit by bit :) Its this config and here you can see the path. Thanks ✨ |
Beta Was this translation helpful? Give feedback.
-
Let me explain why your project can't run well. The current community integration solutions don't consider the case of mono repo. so they can't do as well as. But i clone the repo and use my plugin stylex-extend/vite and put the config in following code. every things works well now :D npm install @stylex-extend/vite -D
// vite.config.js
import { stylex } from '@stylex-extend/vite'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [
..., // your plugins
stylex({ importSources: ['@repo/ui'] })
]
}) and i changed @tilnea I think you can have a try (Maybe helpful) |
Beta Was this translation helpful? Give feedback.
-
Some integrated help for developers:
Here are some code snippets where i solved this prolem (I hope it can helps other developers) // Note: for rollup/vite
const rewriteImportStmts = async (code: string, id: string, ctx: RollupPluginContext, plugins: BabelParserPlugins = []) => {
const stmts = parseStmts(code, id, plugins)
let i = 0
for (const stmt of stmts) {
const { n } = stmt
if (n) {
if (isPotentialCSSFile(n)) { continue }
if (path.isAbsolute(n) || n[0] === '.') {
continue
}
// respect the import sources
if (!options.importSources?.some((i) => n.includes(typeof i === 'string' ? i : i.from))) {
continue
}
const resolved = await ctx.resolve(n, id)
if (resolved && resolved.id && !resolved.external) {
if (resolved.id === id) {
continue
}
if (!resolved.id.includes('node_modules')) {
const p = './' + normalizePath(path.relative(path.dirname(id), resolved.id).replace(/\.\w+$/, ''))
const start = stmt.s + i
const end = stmt.e + i
code = code.slice(0, start) + p + code.slice(end)
i += p.length - (end - start)
}
}
}
}
return code
} |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm working in a turborepo, and I have a file
theme.stylex.ts
that has a lot of theme variables looking similar thisI'm exporting it from my ui package like this
I'm using Vite in my projects, and my
vite.config.js
looks something like thisCreating and working with StyleX in this project works fine, but when I try to import my
baseColors
I get this errorAny idea how I can get it to work?
Beta Was this translation helpful? Give feedback.
All reactions