Skip to content

Commit b9ba779

Browse files
committed
docs: update README
1 parent 9ce290c commit b9ba779

File tree

1 file changed

+65
-9
lines changed

1 file changed

+65
-9
lines changed

README.md

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @rsbuild/plugin-vue2-jsx
22

3-
@rsbuild/plugin-vue2-jsx is a Rsbuild plugin to do something.
3+
Provides support for Vue 2 JSX / TSX syntax. The plugin internally integrates [@vue/babel-preset-jsx](https://github.com/vuejs/jsx-vue2).
44

55
<p>
66
<a href="https://npmjs.com/package/@rsbuild/plugin-vue2-jsx">
@@ -21,26 +21,82 @@ Add plugin to your `rsbuild.config.ts`:
2121

2222
```ts
2323
// rsbuild.config.ts
24+
import { pluginBabel } from "@rsbuild/plugin-babel";
25+
import { pluginVue2 } from "@rsbuild/plugin-vue2";
2426
import { pluginVue2Jsx } from "@rsbuild/plugin-vue2-jsx";
2527

2628
export default {
27-
plugins: [pluginVue2Jsx()],
29+
plugins: [
30+
pluginBabel({
31+
include: /\.(?:jsx|tsx)$/,
32+
}),
33+
pluginVue2(),
34+
pluginVue2Jsx(),
35+
],
2836
};
2937
```
3038

39+
Since the Vue JSX plugin relies on Babel for compilation, you need to additionally add the [@rsbuild/plugin-babel](https://www.npmjs.com/package/@rsbuild/plugin-babel).
40+
41+
Babel compilation will introduce extra overhead, in the example above, we use `include` to match `.jsx` and `.tsx` files, thereby reducing the performance cost brought by Babel.
42+
43+
After registering the plugin, you can use Vue's [JSX / TSX syntax](https://github.com/vuejs/jsx-vue2) in `.jsx`, `.tsx`, and `.vue` files.
44+
45+
## Vue SFC
46+
47+
When using JSX in Vue SFC, you need to add `lang="jsx"` or `lang="tsx"` to the `<script>` tag.
48+
49+
- JSX:
50+
51+
```html title="App.vue"
52+
<script lang="jsx">
53+
const vnode = <div>hello</div>;
54+
</script>
55+
```
56+
57+
- TSX:
58+
59+
```html title="App.vue"
60+
<script lang="tsx">
61+
const vnode = <div>hello</div>;
62+
</script>
63+
```
64+
3165
## Options
3266

33-
### foo
67+
If you need to customize the compilation behavior of Vue JSX, you can use the following configs.
68+
69+
### vueJsxOptions
3470

35-
Some description.
71+
Options passed to `@vue/babel-preset-jsx`, please refer to the [@vue/babel-preset-jsx documentation](https://github.com/vuejs/jsx-vue2) for detailed usage.
3672

37-
- Type: `string`
38-
- Default: `undefined`
39-
- Example:
73+
- **Type:**
4074

41-
```js
75+
```ts
76+
type VueJSXPresetOptions = {
77+
compositionAPI?: boolean | string;
78+
functional?: boolean;
79+
injectH?: boolean;
80+
vModel?: boolean;
81+
vOn?: boolean;
82+
};
83+
```
84+
85+
- **Default:**
86+
87+
```ts
88+
const defaultOptions = {
89+
injectH: true,
90+
};
91+
```
92+
93+
- **Example:**
94+
95+
```ts
4296
pluginVue2Jsx({
43-
foo: "bar",
97+
vueJsxOptions: {
98+
injectH: false,
99+
},
44100
});
45101
```
46102

0 commit comments

Comments
 (0)