-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
index.ts
47 lines (39 loc) · 1.04 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { createUnplugin } from 'unplugin'
import {
type BaseOptions,
type MarkRequired,
REGEX_SETUP_SFC,
REGEX_VUE_SFC,
REGEX_VUE_SUB,
createFilter,
detectVueVersion,
} from '@vue-macros/common'
import { transformDefineOptions } from './core'
export type Options = BaseOptions
export type OptionsResolved = MarkRequired<Options, 'include' | 'version'>
function resolveOption(options: Options): OptionsResolved {
const version = options.version || detectVueVersion()
return {
include: [REGEX_VUE_SFC, REGEX_SETUP_SFC, REGEX_VUE_SUB],
...options,
version,
}
}
const name = 'unplugin-vue-define-options'
export default createUnplugin<Options | undefined, false>(
(userOptions = {}) => {
const options = resolveOption(userOptions)
const filter = createFilter(options)
return {
name,
enforce: 'pre',
transformInclude(id) {
return filter(id)
},
transform(code, id) {
return transformDefineOptions(code, id)
},
}
}
)
export { transformDefineOptions as transform }