Skip to content

Commit 32fd01f

Browse files
authored
feat: add jsx support (#3)
1 parent 774684b commit 32fd01f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+961
-1060
lines changed
File renamed without changes.

.github/workflows/release.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
steps:
14+
- uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0
17+
18+
- uses: actions/setup-node@v3
19+
with:
20+
node-version: lts/*
21+
22+
- run: npx changelogithub
23+
env:
24+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,5 @@ dist
128128
.yarn/build-state.yml
129129
.yarn/install-state.gz
130130
.pnp.*
131+
132+
.DS_Store

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"typescript.tsdk": "node_modules/typescript/lib",
3+
"prettier.enable": false
4+
}

README.md

Lines changed: 197 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,198 @@
11
# unplugin-vue-source
2-
Add a __source prop to all Elements
2+
3+
Add a \_\_source prop to all Elements.
4+
5+
- 🌈 Supports `Vue2` and `Vue3`.
6+
- 🪐 Support add to `<Component/>`.
7+
- ✨ JSX support in `.vue`, `.jsx`, `.tsx`.
8+
- 😃 Supports `Vite`, `Webpack`, `Rspack`, `Vue CLI`, `Rollup`, `esbuild`.
9+
10+
---
11+
12+
sfc without
13+
14+
```html
15+
<!-- /src/App.vue -->
16+
<template>
17+
<div>hello word</div>
18+
</template>
19+
```
20+
21+
with
22+
23+
```html
24+
<!-- /src/App.vue -->
25+
<template>
26+
<div __source="/src/App.vue:3:3">hello word</div>
27+
</template>
28+
```
29+
30+
---
31+
32+
jsx without
33+
34+
```tsx
35+
// /src/App.vue
36+
export default App() {
37+
return <div>hello word</div>
38+
}
39+
```
40+
41+
with
42+
43+
```tsx
44+
// /src/App.vue
45+
export default App() {
46+
return <div __source="/src/App.vue:3:9">hello word</div>
47+
}
48+
```
49+
50+
## Install
51+
52+
```bash
53+
npm i -D unplugin-vue-source
54+
```
55+
56+
## Vue2
57+
58+
```ts
59+
// main.ts
60+
import Vue from 'vue';
61+
import VueSource from "unplugin-vue-source/vue";
62+
import App from "./App.vue";
63+
64+
Vue.use(VueSource);
65+
66+
new Vue({
67+
el: "#app",
68+
render: (h) => h(App),
69+
});
70+
```
71+
72+
## Vue3
73+
74+
```ts
75+
// main.ts
76+
import { createApp } from 'vue';
77+
import VueSource from "unplugin-vue-source/vue";
78+
import App from "./App.vue";
79+
80+
const app = createApp(App);
81+
app.use(VueSource);
82+
app.mount("#app");
83+
```
84+
85+
## Plugins
86+
87+
<details>
88+
<summary>Vite</summary><br>
89+
90+
```ts
91+
// vite.config.ts
92+
import VueSource from "unplugin-vue-source/vite";
93+
94+
export default defineConfig({
95+
plugins: [
96+
VueSource({ /* options */ }),
97+
// other plugins
98+
],
99+
});
100+
```
101+
102+
<br></details>
103+
104+
<details>
105+
<summary>Rollup</summary><br>
106+
107+
```ts
108+
// rollup.config.js
109+
import VueSource from "unplugin-vue-source/rollup";
110+
111+
export default {
112+
plugins: [
113+
VueSource({ /* options */ }),
114+
// other plugins
115+
],
116+
};
117+
```
118+
119+
<br></details>
120+
121+
<details>
122+
<summary>Webpack</summary><br>
123+
124+
```ts
125+
// webpack.config.js
126+
module.exports = {
127+
plugins: [
128+
require("unplugin-vue-source/webpack")({ /* options */ }),
129+
// other plugins
130+
],
131+
};
132+
```
133+
134+
<br></details>
135+
136+
<details>
137+
<summary>Rspack</summary><br>
138+
139+
```ts
140+
// rspack.config.js
141+
module.exports = {
142+
plugins: [
143+
require("unplugin-vue-source/rspack")({ /* options */ }),
144+
// other plugins
145+
],
146+
};
147+
```
148+
149+
<br></details>
150+
151+
<details>
152+
<summary>Vue CLI</summary><br>
153+
154+
```ts
155+
// vue.config.js
156+
module.exports = {
157+
configureWebpack: {
158+
plugins: [
159+
require("unplugin-vue-source/webpack")({ /* options */ }),
160+
// other plugins
161+
],
162+
},
163+
};
164+
```
165+
166+
<br></details>
167+
168+
<details>
169+
<summary>esbuild</summary><br>
170+
171+
```ts
172+
// esbuild.config.js
173+
import { build } from "esbuild";
174+
import VueSource from "unplugin-vue-source/esbuild";
175+
176+
build({
177+
plugins: [
178+
VueSource({ /* options */ }),
179+
// other plugins
180+
],
181+
});
182+
```
183+
184+
<br></details>
185+
186+
## Configuration
187+
188+
The following show the default values of the configuration
189+
190+
```ts
191+
VueSource({
192+
// source root path
193+
root: process.cwd(),
194+
195+
// generate sourceMap
196+
sourceMap: false,
197+
})
198+
```

examples/rollup/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
"rollup-plugin-live-server": "^2.0.0",
2121
"rollup-plugin-postcss": "^4.0.2",
2222
"rollup-plugin-svg": "^2.0.0",
23-
"rollup-plugin-vue": "^5.0.0",
2423
"typescript": "^2.2.0",
25-
"unplugin-vue-source": "workspace:*"
24+
"unplugin-vue-jsx": "^0.2.2",
25+
"unplugin-vue-source": "workspace:*",
26+
"unplugin-vue2": "^0.1.1"
2627
}
2728
}

examples/rollup/rollup.config.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import babel from "@rollup/plugin-babel";
44
import replace from "@rollup/plugin-replace";
55
import postcss from "rollup-plugin-postcss";
66
import svg from "rollup-plugin-svg";
7-
import vue from "rollup-plugin-vue";
8-
import { liveServer } from "rollup-plugin-live-server";
7+
import Vue2 from "unplugin-vue2/rollup";
8+
import VueJsx from "unplugin-vue-jsx/rollup";
99
import VueSource from "unplugin-vue-source/rollup";
10+
import { liveServer } from "rollup-plugin-live-server";
1011

1112
const extensions = [
1213
".js",
@@ -26,24 +27,26 @@ export default {
2627
format: "esm",
2728
},
2829
plugins: [
29-
VueSource({}),
30-
vue({
31-
exposeFilename: true,
30+
VueSource(),
31+
VueJsx({
32+
version: 2,
3233
}),
34+
Vue2(),
35+
postcss(),
36+
3337
commonjs(),
3438
resolve({
3539
extensions,
3640
}),
3741
replace({
3842
preventAssignment: true,
3943
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
40-
}),
44+
}),
4145
babel({
4246
babelHelpers: "bundled",
4347
extensions,
4448
presets: ["@babel/preset-env", "@babel/preset-typescript"],
4549
}),
46-
postcss(),
4750
svg({
4851
base64: true,
4952
}),

examples/rollup/src/App.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
<script lang="ts">
2-
import Vue from 'vue';
3-
import HelloWorld from './components/HelloWorld.vue';
1+
<script lang="tsx">
2+
import Vue from "vue";
3+
import HelloWorld from "./components/HelloWorld";
44
55
export default Vue.extend({
66
components: {
77
HelloWorld,
88
},
9+
910
});
1011
</script>
1112

@@ -19,7 +20,7 @@ export default Vue.extend({
1920
<img src="../public/vue.svg" class="logo vue" alt="Vue logo" />
2021
</a>
2122
</div>
22-
<HelloWorld msg="Rollup + Vue2" />
23+
<HelloWorld msg="Roolup + Vue" />
2324
</div>
2425
</template>
2526

@@ -30,9 +31,11 @@ export default Vue.extend({
3031
will-change: filter;
3132
transition: filter 300ms;
3233
}
34+
3335
.logo:hover {
3436
filter: drop-shadow(0 0 2em #646cffaa);
3537
}
38+
3639
.logo.vue:hover {
3740
filter: drop-shadow(0 0 2em #42b883aa);
3841
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { defineComponent } from "vue";
2+
3+
export default defineComponent({
4+
props: { msg: String },
5+
render() {
6+
return (
7+
<div>
8+
<h1>{this.msg}</h1>
9+
<p>
10+
<a target="_black" href="https://github.com/zjxxxxxxxxx/unplugin-vue-source">
11+
Github
12+
</a>
13+
</p>
14+
</div>
15+
);
16+
},
17+
})

examples/rollup/src/components/HelloWorld.vue

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)