Skip to content

Commit ad5aaa2

Browse files
committed
Add readme for babel-plugin-htm
1 parent 181f605 commit ad5aaa2

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# `babel-plugin-htm`
2+
3+
A Babel plugin that compiles [htm] syntax to hyperscript, React.createElement, or just plain objects.
4+
5+
## Usage
6+
7+
Basic usage:
8+
9+
```js
10+
[
11+
["htm", {
12+
"pragma": "React.createElement"
13+
}]
14+
]
15+
```
16+
17+
```js
18+
// input:
19+
html`<div id="foo">hello ${you}</div>`
20+
21+
// output:
22+
React.createElement("div", { id: "foo" }, "hello ", you)
23+
```
24+
25+
## options
26+
27+
### `pragma`
28+
29+
The target "hyperscript" function to compile elements to (see [Babel docs]).
30+
Defaults to: `"h"`.
31+
32+
### `pragma=false` _(experimental)_
33+
34+
Setting `pragma` to `false` changes the output to be plain objects instead of `h()` function calls:
35+
36+
```js
37+
// input:
38+
html`<div id="foo">hello ${you}</div>`
39+
// output:
40+
{ tag:"div", props:{ id: "foo" }, children:["hello ", you] }
41+
```
42+
43+
### `monomorphic` _(experimental)_
44+
45+
Like `pragma=false` but converts all inline text to objects, resulting in the same object shape being used:
46+
47+
```js
48+
// input:
49+
html`<div id="foo">hello ${you}</div>`
50+
// output:
51+
{ type: 1, tag:"div", props:{ id: "foo" }, text: null, children:[
52+
{ type: 3, tag: null, props: null, text "hello ", children: null },
53+
you
54+
] }
55+
```
56+
57+
58+
[htm]: https://github.com/developit/htm
59+
[Babel docs]: https://babeljs.io/docs/en/babel-plugin-transform-react-jsx#pragma

0 commit comments

Comments
 (0)