|
1 | 1 | import { createFilter } from '@rollup/pluginutils'
|
2 |
| -import { createUnplugin, type UnpluginOptions } from 'unplugin' |
| 2 | +import { |
| 3 | + createUnplugin, |
| 4 | + type UnpluginInstance, |
| 5 | + type UnpluginOptions, |
| 6 | +} from 'unplugin' |
3 | 7 | import {
|
4 | 8 | resolveOption,
|
5 | 9 | type Options,
|
6 | 10 | type OptionsResolved,
|
7 | 11 | } from './core/options'
|
8 | 12 |
|
9 |
| -export default createUnplugin<Options | undefined>((userOptions = {}) => { |
10 |
| - let options: OptionsResolved |
11 |
| - let filter: (id: unknown) => boolean |
12 |
| - |
13 |
| - const name = 'unplugin-vue-jsx' |
14 |
| - const factory: UnpluginOptions = { |
15 |
| - name, |
16 |
| - |
17 |
| - async buildStart() { |
18 |
| - options = await resolveOption(userOptions) |
19 |
| - filter = createFilter(options.include, options.exclude) |
20 |
| - }, |
21 |
| - |
22 |
| - transformInclude(id) { |
23 |
| - return filter(id) |
24 |
| - }, |
25 |
| - |
26 |
| - async transform(code, id) { |
27 |
| - let result: { code: string; map: any } | undefined |
28 |
| - if (options.version === 2) { |
29 |
| - // Vue 2 |
30 |
| - const { transformVue2 } = await import('./core/vue2') |
31 |
| - result = await transformVue2(code, id, options) |
32 |
| - } else { |
33 |
| - // Vue 3 |
34 |
| - const { transformVue3 } = await import('./core/vue3') |
35 |
| - result = await transformVue3(code, id, options) |
36 |
| - } |
37 |
| - |
38 |
| - if (!result?.code) return |
39 |
| - return { |
40 |
| - code: result.code, |
41 |
| - map: result.map as any, |
42 |
| - } |
43 |
| - }, |
44 |
| - |
45 |
| - vite: { |
46 |
| - configResolved(config) { |
47 |
| - userOptions.root = config.root |
48 |
| - userOptions.sourceMap = |
49 |
| - config.command === 'serve' || !!config.build.sourcemap |
| 13 | +const VueJsx: UnpluginInstance<Options | undefined, false> = createUnplugin( |
| 14 | + (userOptions = {}) => { |
| 15 | + let options: OptionsResolved |
| 16 | + let filter: (id: unknown) => boolean |
| 17 | + |
| 18 | + const name = 'unplugin-vue-jsx' |
| 19 | + const factory: UnpluginOptions = { |
| 20 | + name, |
| 21 | + |
| 22 | + async buildStart() { |
| 23 | + options = await resolveOption(userOptions) |
| 24 | + filter = createFilter(options.include, options.exclude) |
| 25 | + }, |
| 26 | + |
| 27 | + transformInclude(id) { |
| 28 | + return filter(id) |
| 29 | + }, |
| 30 | + |
| 31 | + async transform(code, id) { |
| 32 | + let result: { code: string; map: any } | undefined |
| 33 | + if (options.version === 2) { |
| 34 | + // Vue 2 |
| 35 | + const { transformVue2 } = await import('./core/vue2') |
| 36 | + result = await transformVue2(code, id, options) |
| 37 | + } else { |
| 38 | + // Vue 3 |
| 39 | + const { transformVue3 } = await import('./core/vue3') |
| 40 | + result = await transformVue3(code, id, options) |
| 41 | + } |
| 42 | + |
| 43 | + if (!result?.code) return |
| 44 | + return { |
| 45 | + code: result.code, |
| 46 | + map: result.map as any, |
| 47 | + } |
| 48 | + }, |
| 49 | + |
| 50 | + vite: { |
| 51 | + configResolved(config) { |
| 52 | + userOptions.root = config.root |
| 53 | + userOptions.sourceMap = |
| 54 | + config.command === 'serve' || !!config.build.sourcemap |
| 55 | + }, |
50 | 56 | },
|
51 |
| - }, |
52 |
| - } |
| 57 | + } |
53 | 58 |
|
54 |
| - return factory |
55 |
| -}) |
| 59 | + return factory |
| 60 | + }, |
| 61 | +) |
| 62 | +export default VueJsx |
0 commit comments