vue-jsx-runtime
Vue 3 jsx runtime support.
The background https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html . With new jsx runtime support, which means a JSX ast standard, every lib can have its own jsx syntax with small limits.
Examples with TS:
TODO:
- optimize, transformOn, isCustomElement ...
- dev validation
- more tests
- more features
Installation
Install the plugin with:
Usage
In Babel
In TypeScript
tsconfig.json
:
If you used with Babel, you need to set the config:
In Other Tools
If you use some tool which support jsx-runtime, like swc, you can use like this:
.swcrc
:
More details, see https://swc.rs/docs/configuration/compilation#jsctransformreact
About esbuild, see https://github.com/evanw/esbuild/issues/1172 and a hack way https://github.com/evanw/esbuild/issues/832 . https://github.com/evanw/esbuild/issues/334#issuecomment-711444731 .
Syntax
Content
Functional component:
with render
Fragment
Attributes / Props
with a dynamic binding:
Directives
v-show
v-model
A little different with @vue/babel-plugin-jsx
.
Syntax:
v-model={[object, ["path/key"], argument, ["modifier"]]}
Recommend:
v-model
will use val["value"]
to getter or setter by default.
Other usage
Will compile to:
custom directive
Recommended when using string arguments
Slot
Recommend
Use object slots:
Use v-slots
Note: In
jsx
,v-slot
should be replace withv-slots
Different with vue jsx-next
jsx-next
is a plugin forBabel
only.vue-jsx-runtime
can be used withBabel
,TypeScript
,swc
,esbuild
and more.
vue-jsx-runtime
limits:
- can not merge ele/component props
v-model
syntax is little different withjsx-next
-v-model