Skip to content

Commit c860205

Browse files
authored
Merge pull request #182 from bcomnes/jsx
Add support for tsx/jsx defaulting to preact
2 parents 22ee497 + dd7338c commit c860205

File tree

14 files changed

+73
-9
lines changed

14 files changed

+73
-9
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ src % tree
7070
│ ├── client.js # nested pages are just pages, so they also can have a page scoped client and style.
7171
│ └── style.css
7272
├── html-page
73-
│ ├── client.js
73+
│ ├── client.jsx # client bundles can also be written in .jsx/.tsx
7474
│ ├── page.html # Raw html pages are also supported. They support handlebars template blocks.
7575
│ ├── page.vars.js # pages can define page variables in a page.vars.js.
7676
│ └── style.css
@@ -316,6 +316,10 @@ await someHelper()
316316
await funnyLibrary()
317317
```
318318

319+
#### .tsx/.jsx
320+
321+
Client bundles support .jsx and .tsx. They default to preact, so if you want mainlain recat, customize your esbuild settings to load that instead.
322+
319323
### Page variable files
320324

321325
Each page can also have a `page.vars.js` file that exports a `default` function or object that contains page specific variables.
@@ -1184,7 +1188,7 @@ Some notable features are included below, see the [roadmap](https://github.com/u
11841188
- [x] Esbuild settings escape hatch
11851189
- [x] Copy folders
11861190
- [x] Full Typescript support via native type stripping
1187-
- [ ] JSX support in client bundles
1191+
- [x] JSX+TSX support in client bundles
11881192
- ...[See roadmap](https://github.com/users/bcomnes/projects/3/)
11891193

11901194
## History

examples/preact/src/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
This is a preact example.
44

5-
[Isomorphic Component Rendering](./isomorphic/)
5+
- [Isomorphic Component Rendering](./isomorphic/)
6+
- [JSX-page](./jsx-page/)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { render } from 'preact'
2+
3+
export const page = () => {
4+
return (
5+
<div>
6+
look ma, client side jsx!
7+
</div>
8+
)
9+
}
10+
11+
const renderTarget = document.querySelector('.jsx-app')
12+
render(page(), renderTarget)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div>
2+
<h2>This is an html page, with a client.jsx that mounts onto it</h2>
3+
<div class="jsx-app"></div>
4+
</div>

examples/type-stripping/src/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
This is a preact example.
44

5-
[Isomorphic Component Rendering](./isomorphic/)
5+
- [Isomorphic Component Rendering](./isomorphic/)
6+
- [tsx-client]('./isomorphic/')
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { render } from 'preact'
2+
3+
export const page = () => {
4+
return (
5+
<div>
6+
look ma, client side jsx!
7+
</div>
8+
)
9+
}
10+
11+
const renderTarget = document.querySelector('.jsx-app')
12+
if (renderTarget) {
13+
render(page(), renderTarget)
14+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div>
2+
<h2>This is an html page, with a client.jsx that mounts onto it</h2>
3+
<div class="jsx-app"></div>
4+
</div>

examples/type-stripping/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"erasableSyntaxOnly": true,
66
"allowImportingTsExtensions": true,
77
"rewriteRelativeImportExtensions": true,
8-
"verbatimModuleSyntax": true
8+
"verbatimModuleSyntax": true,
9+
"jsx": "react-jsx",
10+
"jsxImportSource": "preact"
911
},
1012
"include": [
1113
"**/*",

lib/build-esbuild/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ export async function buildEsbuild (src, dest, siteData, opts) {
9191
metafile: true,
9292
entryNames: '[dir]/[name]-[hash]',
9393
chunkNames: 'chunks/[ext]/[name]-[hash]',
94+
jsx: 'automatic',
95+
jsxImportSource: 'preact'
9496
}
9597

9698
const esbuildSettingsExtends = siteData.esbuildSettings

lib/identify-pages.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const jsPageDraftNames = hasTS
3131
: ['page.draft.js', 'page.draft.mjs', 'page.draft.cjs']
3232

3333
const pageClientNames = hasTS
34-
? ['client.ts', 'client.mts', 'client.cts', 'client.js', 'client.mjs', 'client.cjs']
35-
: ['client.js', 'client.mjs', 'client.cjs']
34+
? ['client.tsx', 'client.ts', 'client.mts', 'client.cts', 'client.jsx', 'client.js', 'client.mjs', 'client.cjs']
35+
: ['client.jsx', 'client.js', 'client.mjs', 'client.cjs']
3636

3737
const pageVarsNames = hasTS
3838
? ['page.vars.ts', 'page.vars.mts', 'page.vars.cts',

0 commit comments

Comments
 (0)