Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSX Engine #235

Closed
dj opened this issue Sep 17, 2018 · 9 comments
Closed

Add JSX Engine #235

dj opened this issue Sep 17, 2018 · 9 comments

Comments

@dj
Copy link

dj commented Sep 17, 2018

Would you be open to a PR to include JSX as an engine? I think I get the gist for how one would be implemented, looking at the code (but would love any pointers on how to implement).

The idea would be to use ReactDOMServer.renderToStaticMarkup()

@zachleat
Copy link
Member

Yeah! I think this would be useful.

Related, planning on making this easier in #117.

@zachleat zachleat added enhancement needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved. labels Sep 19, 2018
@zachleat
Copy link
Member

This repository is now using lodash style issue management for enhancements. This means enhancement issues will now be closed instead of leaving them open.

The enhancement backlog can be found here: https://github.com/11ty/eleventy/issues?utf8=%E2%9C%93&q=label%3Aneeds-votes+sort%3Areactions-%2B1-desc+

Don’t forget to upvote the top comment with 👍!

@elbotho
Copy link

elbotho commented May 31, 2019

👍
This might be a nice small solution without react:
https://github.com/developit/vhtml

@wommy
Copy link

wommy commented Aug 29, 2019

how does react-static do it?

@ithinkihaveacat
Copy link
Contributor

Here's an example of how to use JSX (or the TypeScript variant, TSX) with Eleventy via JavaScript templates (*.11ty.js):

https://github.com/ithinkihaveacat/eleventy-jsx

(It uses vhtml!)

@signalkuppe
Copy link

signalkuppe commented Aug 22, 2020

Just published a starter kit that uses react components as the default template language

https://github.com/signalkuppe/eleventy-react

Feedbacks are welcome!

@jahilldev
Copy link

jahilldev commented Sep 28, 2020

I've managed to get JSX support using a simple config.addTransform method in the config file.

The important bit is here:
https://github.com/jhukdev/11tyboo/blob/master/.eleventy.js#L19

I'm using Preact in the repo above.

Both React and Preact have an isValidElement function that can be used to conditionally apply render to React.createElement calls (or h() for Preact).

Once that's setup you can return JSX from your *.11ty.jsx or *11ty.tsx files and it'll be handled for you.

I've only done this using TypeScript's JSX factory, but I'm sure you could replace that with a Babel transform / plugin.

@j-f1
Copy link
Contributor

j-f1 commented Feb 15, 2022

I used the new template language support of Eleventy v1.0 to make a plugin that enables JSX support using Babel and the excellent @unifiedjs​/@rehypejs ecosystem. Check it out here: https://github.com/j-f1/eleventy-hast-jsx. My hope is that it will be pretty generic but let me know if you need it to do anything else!

@zachleat zachleat added this to the Eleventy 3.0.0 milestone Jun 2, 2024
@zachleat
Copy link
Member

zachleat commented Jun 2, 2024

Official docs deploying to https://www.11ty.dev/docs/languages/jsx/ Shipping with 3.0.0-alpha.11

Very open to others adding alternate approaches there, via plugins or otherwise!

@zachleat zachleat removed the needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved. label Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants