An open API service indexing awesome lists of open source software.

https://github.com/unplugin/unplugin-vue-jsx-vapor


https://github.com/unplugin/unplugin-vue-jsx-vapor

Last synced: 4 months ago
JSON representation

Awesome Lists containing this project

README

        

# unplugin-vue-jsx-vapor

[![NPM version](https://img.shields.io/npm/v/unplugin-vue-jsx-vapor?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-vue-jsx-vapor)

Vue JSX Vapor.

[REPL](https://repl.zmjs.dev/vue-jsx-vapor)

## Install

```bash
npm i unplugin-vue-jsx-vapor
```

> [!CAUTION]
> ❌ The destructuring of props in a functional component will cause loss of reactivity.

```tsx
function Comp({ foo }) {
return

{foo}

}

export default () => {
const foo = ref('foo')
return
}
```

#### Two Solutions

1. ✅ Pass a ref variable as prop:

```tsx
function Comp({ foo }) {
return

{foo.value}

}

export default () => {
const foo = ref('foo')
return
}
```

2. ✅ Use the `defineComponent` macro from [@vue-macros/jsx-macros](https://github.com/vue-macros/vue-macros/pull/794) to wrapping.

```tsx
const Comp = defineComponent(({ foo }) => {
return <>{foo}>
})
// Will be convert to:
const Comp = defineComponent((_props) => {
return <>{_props.foo}>
}, { props: ['foo'] })

export default () => {
const foo = ref('foo')
return
}
```

Vite

```ts
// vite.config.ts
import VueJsxVapor from 'unplugin-vue-jsx-vapor/vite'

export default defineConfig({
plugins: [VueJsxVapor()],
})
```

Example: [`playground/`](./playground/)


Rollup

```ts
// rollup.config.js
import VueJsxVapor from 'unplugin-vue-jsx-vapor/rollup'

export default {
plugins: [VueJsxVapor()],
}
```


Webpack

```ts
// webpack.config.js
module.exports = {
/* ... */
plugins: [require('unplugin-vue-jsx-vapor/webpack')()],
}
```


Nuxt

```ts
// nuxt.config.js
export default defineNuxtConfig({
modules: ['unplugin-vue-jsx-vapor/nuxt'],
})
```

> This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite)


Vue CLI

```ts
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [require('unplugin-vue-jsx-vapor/webpack')()],
},
}
```


esbuild

```ts
// esbuild.config.js
import { build } from 'esbuild'
import VueJsxVapor from 'unplugin-vue-jsx-vapor/esbuild'

build({
plugins: [VueJsxVapor()],
})
```