Replies: 4 comments 5 replies
-
Hey @nmn, your proposed solutions should work in real-world scenarios, and just walking up the directory path should not hamper the build time too. Also, I'm pretty close to fixing the aliases issue. And if we can pass the config for aliases from the plugin options for now, I think I might be able to share a PR for this fix tomorrow 🤞. |
Beta Was this translation helpful? Give feedback.
-
This is one of my bigger concerns and I'm unsure if it makes sense to use the synchronous or asynchronous File APIs for this. |
Beta Was this translation helpful? Give feedback.
-
I'd like to throw a spanner in here by considering how stylex would work with nextjs in an nxdev monorepo. packages in an nxdev monorepo: https://github.com/airtonix/nx-stylex-issues/tree/master
another spanner which may or may not affect your thinking is preconstruct.dev which ends up doing some kind of babel faking typescript shimming in local dev mode for packages. |
Beta Was this translation helpful? Give feedback.
-
Are these two issues related at all? #297 It's just I don't have any problems incorporating styleX in the appdir, nor in a packages folder with turborepo. However, when I am working with my own complex component library. No styles are generated for any components that are imported into the application and are running from the /dist folder (of the package). This is even the case when using transpilepackages. I've tested Griffel, which seems fine and without needing transpilepackages. I just want to mention that. So you don't think it's a misconfiguration on my end. 😄 My question is this. On this issue and #297. When do you think these may be resolved? I understand that with the latter there maybe things outside of your control. It's just that I'm using unocss right now. It doesn't scale for me. StyleX might seem like a way forward but I'd like to see these issues dealt with before I commit a lot of time doing a poc to see if I can migrate over. Many thanks! |
Beta Was this translation helpful? Give feedback.
-
Problem
One of the challenging parts of using StyleX today is importing
VarGroup
s from.stylex.js
files. There are three details that are less than ideal:rootDir
to be set in the Babel configuration should match the root directory of the project.rootDir
is different on different machines. Making the built artifacts less portable.require.resolve
so custom@/foo.stylex.js
imports set up by frameworks like Next don't work.Proposal
The idea is to remove the requirement for
rootDir
and instead rely onpackage.json
files.When importing a file, we would resolve the file being imported, walk up the directory path until we find a
package.json
file and then use the<package-name>/<path-to-file-within>
as the key to hash to generate variable names. This will be used both for defining and exporting, and when importing variables. (We don't need to read the file itself. Just the file path)This should solve problem 1 and 2 mentioned above. All files within your own project would walk up to to the nearest
package.json
file and have a consistent hash. All files in NPM packages would walk up to their ownpackage.json
file and also have consistent hashes. The hashes won't change regardless of whether thenode_modules
are actually local or just links to a global cache.Possible Pitfall
This proposal makes two assumptions:
package.json
file.package.json
file is unique.Solving Aliases
We could accept a simple object of aliases to rename imports before trying to resolve them in the Babel plugin. We can later figure out how to read the Next.js configuration and set this automatically in the NextJS plugin.
Beta Was this translation helpful? Give feedback.
All reactions