Skip to content

Commit d117d0f

Browse files
authored
feat: Add option babelParserPlugins (#22)
1 parent 13d1ee0 commit d117d0f

File tree

19 files changed

+146
-80
lines changed

19 files changed

+146
-80
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,12 @@ build({
212212
The following show the default values of the configuration
213213

214214
```ts
215-
interface Options {
215+
export interface Options {
216+
/** @default '**\/*.{vue,jsx,tsx}' */
217+
include?: string | RegExp | (string | RegExp)[];
218+
/** @default 'node_modules/**' */
219+
exclude?: string | RegExp | (string | RegExp)[];
220+
216221
/**
217222
* source root path
218223
*
@@ -226,10 +231,12 @@ interface Options {
226231
*/
227232
sourceMap?: boolean;
228233

229-
/** @default '**\/*.{vue,jsx,tsx}' */
230-
include?: string | RegExp | (string | RegExp)[];
231-
/** @default 'node_modules/**' */
232-
exclude?: string | RegExp | (string | RegExp)[];
234+
/**
235+
* Array containing the plugins that you want to enable.
236+
*
237+
* @default ['jsx', 'typescript']
238+
*/
239+
babelParserPlugins?: ParserPlugin[];
233240
}
234241
```
235242

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script lang="tsx">
2+
import { defineComponent } from 'vue';
3+
4+
export default defineComponent({
5+
render() {
6+
return (
7+
<a
8+
target="_black"
9+
href="https://github.com/zjxxxxxxxxx/unplugin-vue-source"
10+
>
11+
Github
12+
</a>
13+
);
14+
},
15+
});
16+
</script>

examples/rollup/src/components/HelloWorld.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineComponent } from 'vue';
2+
import Github from './Github.vue';
23

34
export default defineComponent({
45
props: { msg: String },
@@ -10,12 +11,7 @@ export default defineComponent({
1011
Inspect the element to see the <code>__source</code>
1112
</p>
1213
<p>
13-
<a
14-
target="_black"
15-
href="https://github.com/zjxxxxxxxxx/unplugin-vue-source"
16-
>
17-
Github
18-
</a>
14+
<Github />
1915
</p>
2016
</div>
2117
);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script lang="tsx">
2+
import { defineComponent } from 'vue';
3+
4+
export default defineComponent({
5+
render() {
6+
return (
7+
<a
8+
target="_black"
9+
href="https://github.com/zjxxxxxxxxx/unplugin-vue-source"
10+
>
11+
Github
12+
</a>
13+
);
14+
},
15+
});
16+
</script>

examples/vite/src/components/HelloWorld.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Github from './Github.vue';
2+
13
export default function HelloWorld({ msg }: { msg: string }) {
24
return (
35
<>
@@ -6,12 +8,7 @@ export default function HelloWorld({ msg }: { msg: string }) {
68
Inspect the element to see the <code>__source</code>
79
</p>
810
<p>
9-
<a
10-
target="_black"
11-
href="https://github.com/zjxxxxxxxxx/unplugin-vue-source"
12-
>
13-
Github
14-
</a>
11+
<Github />
1512
</p>
1613
</>
1714
);

examples/vite/vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ export default defineConfig({
1111
jsxFragment: 'Fragment',
1212
jsxInject: "import { h, Fragment } from 'vue';",
1313
},
14+
server: {
15+
port: 3000,
16+
},
1417
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script lang="tsx">
2+
import { defineComponent } from 'vue';
3+
4+
export default defineComponent({
5+
render() {
6+
return (
7+
<a
8+
target="_black"
9+
href="https://github.com/zjxxxxxxxxx/unplugin-vue-source"
10+
>
11+
Github
12+
</a>
13+
);
14+
},
15+
});
16+
</script>

examples/webpack/src/components/HelloWorld.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Github from './Github.vue';
2+
13
export default function HelloWorld({ msg }: { msg: string }) {
24
return (
35
<>
@@ -6,12 +8,7 @@ export default function HelloWorld({ msg }: { msg: string }) {
68
Inspect the element to see the <code>__source</code>
79
</p>
810
<p>
9-
<a
10-
target="_black"
11-
href="https://github.com/zjxxxxxxxxx/unplugin-vue-source"
12-
>
13-
Github
14-
</a>
11+
<Github />
1512
</p>
1613
</>
1714
);

examples/webpack/vue.config.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
const { defineConfig } = require("@vue/cli-service");
1+
const { defineConfig } = require('@vue/cli-service');
22
module.exports = defineConfig({
33
configureWebpack: {
44
plugins: [
5-
require("unplugin-vue-source/webpack")(),
6-
require("unplugin-vue-jsx/webpack")(),
5+
require('unplugin-vue-source/webpack')(),
6+
require('unplugin-vue-jsx/webpack')(),
77
],
88
},
9+
devServer: {
10+
port: 3000,
11+
},
912
});

src/core/index.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { type UnpluginFactory, createUnplugin } from 'unplugin';
22
import { createFilter } from '@rollup/pluginutils';
33
import { type ResolvedOptions, type Options } from '../types';
4-
import { TRACE_ID } from './constants';
54
import { isDev } from './isDev';
65
import { parse_ID } from './parse_ID';
76
import { transform } from './transform';
@@ -21,21 +20,8 @@ export const unpluginFactory: UnpluginFactory<Options> = (options = {}) => {
2120
enforce: 'pre',
2221

2322
transformInclude(id) {
24-
const { file, isSfc, query } = parse_ID(id);
25-
26-
if (query.raw == null && filter(file)) {
27-
if (isSfc && query.type !== 'template') {
28-
return (
29-
// vite-plugin-vue
30-
!query[TRACE_ID] &&
31-
// rollup-plugin-vue
32-
!query['rollup-plugin-vue']
33-
);
34-
}
35-
36-
// vue cli | vue-loader | tsx | jsx
37-
return true;
38-
}
23+
const { file, query } = parse_ID(id);
24+
return query.raw == null && filter(file);
3925
},
4026
transform(code, id) {
4127
return transform(code, id, opts);
@@ -45,10 +31,11 @@ export const unpluginFactory: UnpluginFactory<Options> = (options = {}) => {
4531

4632
function resolveOptions(opts: Options): ResolvedOptions {
4733
return {
48-
root: opts.root ?? process.cwd(),
49-
sourceMap: opts.sourceMap ?? false,
5034
include: opts.include ?? '**/*.{vue,jsx,tsx}',
5135
exclude: opts.exclude ?? 'node_modules/**',
36+
root: opts.root ?? process.cwd(),
37+
sourceMap: opts.sourceMap ?? false,
38+
babelParserPlugins: opts.babelParserPlugins ?? [],
5239
};
5340
}
5441

0 commit comments

Comments
 (0)