Skip to content

Add TSX support, tests, and README.#15

Open
pauleveritt wants to merge 3 commits into11ty:mainfrom
pauleveritt:tsx
Open

Add TSX support, tests, and README.#15
pauleveritt wants to merge 3 commits into11ty:mainfrom
pauleveritt:tsx

Conversation

@pauleveritt
Copy link

No description provided.

tsx/README.md Outdated
}
```

This 11ty template gets `name` and `content` from the passed-in `data` object. If the `content` string comes from an untrusted source, you might want to "purify" it (to prevent XSS.)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does "purification" and preventing XSS need to be mentioned here? It isn't unique to this template language right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with removing it. If I don't hear back, I'll do the removal.


## How it works

Eleventy template files ending in `.11ty.tsx` will be processed by this plugin, by means of the [`tsx` project](https://tsx.is). `tsx` turns the template into JSX nodes using the [`esbuild`](https://esbuild.github.io) package.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do they have to end in .11ty.tsx? Seems like an odd constraint...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .11ty part is required by 11ty. The .tsx is connected to tsconfig.json and the compiler. While it might be possible to configure the toolchain to accept another file extension, it would be very atypical.

Either way, it's the choice made by this plugin. Kind of matches other template language plugins, which provide default mappings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it required? I've never used anything but plain .tsx extensions before, so it seems like Eleventy is the only blocker here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Look in the "File Extension" column in the current docs. This is related to their derivation from JavaScript Templates.

11ty thinks these JSX/TSX templates are actually just JavaScript Templates with a different compile property.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh gotcha. And there isn't a way to get Eleventy to think like that and remove the 11ty. part?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a derivation of JavaScript Templates and it follows what Zach has for existing JSX/TSX documentation.

If you'd like, I could tinker with changing the line key: "11ty.js" in tsxConfig.js. Perhaps it isn't important for people to think of these as JavaScript Template types.

pauleveritt and others added 2 commits July 31, 2024 18:18
Fix to my mistaken links to 11ty official repo.

Co-authored-by: uncenter <[email protected]>
@pauleveritt
Copy link
Author

Just checking back on this. I believe the only major open question is: would you like these two languages (TSX, JSX) merged into one PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants