facebook / stylex

StyleX is the styling system for ambitious user interfaces.
https://stylexjs.com
MIT License
8.22k stars 303 forks source link

StyleX Plugin for Bun.sh Bundler #497

Closed husseinzchi closed 3 months ago

husseinzchi commented 3 months ago

Describe the feature request

Description: I would like to request a new feature for StyleX: a plugin for integration with the Bun bundler.

Background: Bun is a fast and lightweight bundler that provides built-in support for JavaScript and TypeScript. It has gained popularity recently due to its performance and simplicity.

Currently, StyleX offers plugins for build tools like Webpack, Rollup, Next.js, and esbuild. However, there is no plugin for Bun yet.

Motivation: Having a StyleX plugin for Bun would provide a seamless integration experience for developers who want to use StyleX with Bun. It would allow them to easily compile and bundle StyleX styles as part of their build process.

The plugin could work similarly to the existing plugins for other build tools. It would extract and compile StyleX styles during the bundling process and generate the necessary CSS files.

Benefits:

Implementation: The implementation details of the plugin would need to be determined by the StyleX team, taking into account the specific requirements and best practices for integrating with Bun.

Additional Information:

Bun official website: https://bun.sh/ Bun repository: https://github.com/oven-sh/bun

nedjulius commented 3 months ago

@husseinzchi I published a plugin for Bun: https://github.com/nedjulius/bun-plugin-stylex. feel free to try it out and report any issues (in the plugin's issue tracker).

I wanted to try the Bun runtime myself so decided to build the plugin independently.

husseinzchi commented 3 months ago

Hi @nedjulius thank you so much for creating this. Sure thing, I will keep you posted asap I test it out.

nmn commented 3 months ago

Thanks for the work on this @nedjulius ! (Please open a PR to add it to the website's ecosystem page)

@husseinzchi Let me know if that works for you! Closing this issue in the meantime.

husseinzchi commented 2 months ago

@nedjulius I think the natural place for the extension should be within StyleX repo here: https://github.com/facebook/stylex/tree/main/packages. Like the other build plugins. This will make it easier to find and use.

nedjulius commented 2 months ago

okay so there are some major issues with the Bun StyleX plugin due to missing feature's in Bun runtime. one of the major ones is that require.resolve API does not work as expected in Bun as it does not support options. the require.resolve with options is the method used by StyleX compiler to resolve variables defined with defineVars.

Bun has its own alternative Bun.resolveSync which supports the passing of root dir as a second argument --one way would be to somehow polyfill the require.resolve during the Bun plugin's build. another course of action (probably the best one) is to implement the options argument in Bun runtime.

right now I wouldn't recommend using the Bun StyleX plugin for any production builds as there may be many other node compatibility-related issues that are not as obvious. however, I will keep on investigating and see what I can do to make the plugin somewhat useful.

nmn commented 2 months ago

The require.resolve bit is the main reason why theming is still marked as unstable in the Babel config. The API itself is stable.