An Rsbuild plugin for Vue 2 JSX / TSX support.
Installations
npm install @rsbuild/plugin-vue2-jsx
Developer Guide
Typescript
Yes
Module System
ESM
Node Version
22.12.0
NPM Version
10.9.0
Score
47.8
Supply Chain
94.1
Quality
91.3
Maintenance
100
Vulnerability
97.9
License
Releases
Contributors
Languages
TypeScript (77.18%)
JavaScript (12.98%)
Vue (9.84%)
Developer
rspack-contrib
Download Statistics
Total Downloads
27,438
Last Day
264
Last Week
1,013
Last Month
4,495
Last Year
21,849
GitHub Statistics
6 Stars
18 Commits
1 Forks
3 Watching
1 Branches
6 Contributors
Bundle Size
1.13 MB
Minified
279.59 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.0.3
Package Id
@rsbuild/plugin-vue2-jsx@1.0.3
Unpacked Size
10.14 kB
Size
3.65 kB
File Count
6
NPM Version
10.9.0
Node Version
22.12.0
Publised On
18 Dec 2024
Total Downloads
Cumulative downloads
Total Downloads
27,438
Last day
57.1%
264
Compared to previous day
Last week
17.7%
1,013
Compared to previous week
Last month
76.6%
4,495
Compared to previous month
Last year
290.9%
21,849
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Peer Dependencies
1
@rsbuild/plugin-vue2-jsx
Provides support for Vue 2 JSX / TSX syntax. The plugin internally integrates @vue/babel-preset-jsx.
Usage
Install:
1npm add @rsbuild/plugin-vue2-jsx -D
Add plugin to your rsbuild.config.ts
:
1// rsbuild.config.ts 2import { pluginBabel } from "@rsbuild/plugin-babel"; 3import { pluginVue2 } from "@rsbuild/plugin-vue2"; 4import { pluginVue2Jsx } from "@rsbuild/plugin-vue2-jsx"; 5 6export default { 7 plugins: [ 8 pluginBabel({ 9 include: /\.(?:jsx|tsx)$/, 10 }), 11 pluginVue2(), 12 pluginVue2Jsx(), 13 ], 14};
Since the Vue JSX plugin relies on Babel for compilation, you need to additionally add the @rsbuild/plugin-babel.
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.
After registering the plugin, you can use Vue's JSX / TSX syntax in .jsx
, .tsx
, and .vue
files.
Vue SFC
When using JSX in Vue SFC, you need to add lang="jsx"
or lang="tsx"
to the <script>
tag.
- JSX:
1<script lang="jsx"> 2 const vnode = <div>hello</div>; 3</script>
- TSX:
1<script lang="tsx"> 2 const vnode = <div>hello</div>; 3</script>
Options
If you need to customize the compilation behavior of Vue JSX, you can use the following configs.
vueJsxOptions
Options passed to @vue/babel-preset-jsx
, please refer to the @vue/babel-preset-jsx documentation for detailed usage.
- Type:
1type VueJSXPresetOptions = { 2 compositionAPI?: boolean | string; 3 functional?: boolean; 4 injectH?: boolean; 5 vModel?: boolean; 6 vOn?: boolean; 7};
- Default:
1const defaultOptions = { 2 injectH: true, 3};
- Example:
1pluginVue2Jsx({ 2 vueJsxOptions: { 3 injectH: false, 4 }, 5});
License
MIT.
No vulnerabilities found.
No security vulnerabilities found.