Skip to content

Commit cb0eed4

Browse files
committed
feat: jsx to template
1 parent 48f1260 commit cb0eed4

29 files changed

+746
-2964
lines changed

README.md

+24-27
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,7 @@
22

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

5-
Starter template for [unplugin](https://github.com/unjs/unplugin).
6-
7-
## Template Usage
8-
9-
To use this template, clone it down using:
10-
11-
```bash
12-
npx degit unplugin/unplugin-vue-jsx-vapor my-unplugin
13-
```
14-
15-
And do a global replacement of `unplugin-vue-jsx-vapor` with your plugin name.
16-
17-
Then you can start developing your unplugin 🔥
18-
19-
To test your plugin, run: `pnpm run dev`
20-
To release a new version, run: `pnpm run release`
5+
Convert JSX to Template for compiler-vapor.
216

227
## Install
238

@@ -30,11 +15,13 @@ npm i unplugin-vue-jsx-vapor
3015

3116
```ts
3217
// vite.config.ts
33-
import Starter from 'unplugin-vue-jsx-vapor/vite'
18+
import VueJsxVapor from 'unplugin-vue-jsx-vapor/vite'
3419

3520
export default defineConfig({
3621
plugins: [
37-
Starter({ /* options */ }),
22+
VueJsxVapor({
23+
/* options */
24+
}),
3825
],
3926
})
4027
```
@@ -48,18 +35,19 @@ Example: [`playground/`](./playground/)
4835

4936
```ts
5037
// rollup.config.js
51-
import Starter from 'unplugin-vue-jsx-vapor/rollup'
38+
import VueJsxVapor from 'unplugin-vue-jsx-vapor/rollup'
5239

5340
export default {
5441
plugins: [
55-
Starter({ /* options */ }),
42+
VueJsxVapor({
43+
/* options */
44+
}),
5645
],
5746
}
5847
```
5948

6049
<br></details>
6150

62-
6351
<details>
6452
<summary>Webpack</summary><br>
6553

@@ -68,8 +56,10 @@ export default {
6856
module.exports = {
6957
/* ... */
7058
plugins: [
71-
require('unplugin-vue-jsx-vapor/webpack')({ /* options */ })
72-
]
59+
require('unplugin-vue-jsx-vapor/webpack')({
60+
/* options */
61+
}),
62+
],
7363
}
7464
```
7565

@@ -82,7 +72,12 @@ module.exports = {
8272
// nuxt.config.js
8373
export default defineNuxtConfig({
8474
modules: [
85-
['unplugin-vue-jsx-vapor/nuxt', { /* options */ }],
75+
[
76+
'unplugin-vue-jsx-vapor/nuxt',
77+
{
78+
/* options */
79+
},
80+
],
8681
],
8782
})
8883
```
@@ -99,7 +94,9 @@ export default defineNuxtConfig({
9994
module.exports = {
10095
configureWebpack: {
10196
plugins: [
102-
require('unplugin-vue-jsx-vapor/webpack')({ /* options */ }),
97+
require('unplugin-vue-jsx-vapor/webpack')({
98+
/* options */
99+
}),
103100
],
104101
},
105102
}
@@ -113,10 +110,10 @@ module.exports = {
113110
```ts
114111
// esbuild.config.js
115112
import { build } from 'esbuild'
116-
import Starter from 'unplugin-vue-jsx-vapor/esbuild'
113+
import VueJsxVapor from 'unplugin-vue-jsx-vapor/esbuild'
117114

118115
build({
119-
plugins: [Starter()],
116+
plugins: [VueJsxVapor()],
120117
})
121118
```
122119

package.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@
9191
"prepublishOnly": "npm run build",
9292
"release": "bumpp && npm publish",
9393
"start": "esno src/index.ts",
94-
"test": "vitest"
94+
"test": "vitest",
95+
"postinstall": "if [ ! -d './core-vapor' ]; then git clone https://github.com/vuejs/core-vapor.git; cd core-vapor; pnpm i; pnpm build; pnpm build-dts; cd ..; pnpm add ./core-vapor/packages/vue; fi"
9596
},
9697
"peerDependencies": {
9798
"@nuxt/kit": "^3",
@@ -122,13 +123,15 @@
122123
}
123124
},
124125
"dependencies": {
125-
"unplugin": "^1.5.1"
126+
"@vue-macros/common": "^1.10.0",
127+
"unplugin": "^1.5.1",
128+
"vue": "link:core-vapor/packages/vue"
126129
},
127130
"devDependencies": {
128-
"@antfu/eslint-config": "^2.2.2",
129131
"@nuxt/kit": "^3.8.2",
130132
"@nuxt/schema": "^3.8.2",
131133
"@types/node": "^20.10.3",
134+
"@typescript-eslint/parser": "^6.18.1",
132135
"bumpp": "^9.2.0",
133136
"chalk": "^5.3.0",
134137
"eslint": "^8.55.0",
@@ -139,7 +142,7 @@
139142
"rollup": "^4.6.1",
140143
"tsup": "^8.0.1",
141144
"typescript": "^5.3.2",
142-
"vite": "^5.0.4",
145+
"vite": "^4.5.1",
143146
"vitest": "^0.34.6",
144147
"webpack": "^5.89.0"
145148
}

playground/App.vue

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<script lang="tsx">
2+
import { defineComponent } from 'vue';
3+
import { ref } from 'vue/vapor'
4+
5+
export default defineComponent({
6+
setup() {
7+
const count = ref(1)
8+
9+
return (
10+
<>
11+
<form onSubmit_prevent>
12+
<input
13+
v-bind:value={count.value}
14+
onInput={(event: any) => count.value=event.target.value}
15+
/>
16+
17+
<div>v-text: <span v-text={count.value}/></div>
18+
<div>v-html: <span v-html={count.value}/></div>
19+
<div>v-once: <span v-once>{count.value}</span></div>
20+
<div>v-pre: <span v-pre>{count.value}</span></div>
21+
<div>v-cloak: <span v-cloak>{count.value}</span></div>
22+
</form>
23+
</>
24+
)
25+
}
26+
})
27+
</script>
28+
29+
<style>
30+
[v-cloak] {
31+
color: red;
32+
}
33+
</style>

playground/index.html

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
</head>
88
<body>
99
<div id="app"></div>
10-
<a href="/__inspect/#/module?id=./main.ts&index=2" target="_blank" style="text-decoration: none; margin-top:10px; display: block;">visit /__inspect/ to inspect the intermediate state</a>
1110
<script type="module" src="./main.ts"></script>
1211
</body>
1312
</html>

playground/macros-global.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="@vue-macros/define-render/macros-global" />

playground/main.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
document.getElementById('app')!.innerHTML = '__UNPLUGIN__'
1+
import { render } from 'vue/vapor'
2+
3+
const modules = import.meta.glob<any>('./*.(vue|js)')
4+
const mod = (modules[`.${location.pathname}`] || modules['./App.vue'])()
5+
6+
mod.then(({ default: mod }) => render(mod, {}, '#app'))

playground/package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
"dev": "nodemon -w '../src/**/*.ts' -e .ts -x vite"
55
},
66
"devDependencies": {
7+
"@vitejs/plugin-vue": "^5.0.2",
8+
"@vue-macros/volar": "^0.18.10",
79
"vite": "^5.0.4",
8-
"vite-plugin-inspect": "^0.8.1"
10+
"vite-plugin-inspect": "^0.8.1",
11+
"@vue-macros/define-render": "^1.5.1",
12+
"@vue-macros/reactivity-transform": "^0.4.2",
13+
"unplugin-vue-jsx-vapor": "workspace:*"
914
}
1015
}

playground/tsconfig.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2017",
4+
"lib": ["esnext", "DOM"],
5+
"module": "esnext",
6+
"jsxImportSource": "vue",
7+
"jsx": "preserve",
8+
"jsxFactory": "h",
9+
"moduleResolution": "node",
10+
"resolveJsonModule": true,
11+
"strict": true,
12+
"strictNullChecks": true,
13+
"esModuleInterop": true
14+
},
15+
"vueCompilerOptions": {
16+
"plugins": [
17+
"@vue-macros/volar/export-render",
18+
"@vue-macros/volar/jsx-directive",
19+
]
20+
},
21+
"exclude": ["dist", "eslint.config.js"]
22+
}

playground/vite.config.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { defineConfig } from 'vite'
22
import Inspect from 'vite-plugin-inspect'
3-
import Unplugin from '../src/vite'
3+
import Vue from '@vitejs/plugin-vue'
4+
import defineRender from '@vue-macros/define-render/vite'
5+
import VueJsxVapor from 'unplugin-vue-jsx-vapor/vite'
46

57
export default defineConfig({
6-
plugins: [
7-
Inspect(),
8-
Unplugin(),
9-
],
8+
plugins: [Vue(), defineRender(), VueJsxVapor(), Inspect()],
109
})

0 commit comments

Comments
 (0)