|
1 | 1 | import { parseTemplate, TemplateMatch } from './parseTemplate'
|
2 |
| -import * as importMap from 'vuetify/dist/json/importMap.json' |
| 2 | +import * as importMap from 'vuetify/dist/json/importMap.json' with { type: 'json' } |
| 3 | +import * as importMapLabs from 'vuetify/dist/json/importMap-labs.json' with { type: 'json' } |
| 4 | +import { isObject } from '../' |
| 5 | +import type { Options } from '../' |
3 | 6 |
|
4 |
| -export function getImports (source: string, ignore: string[] = []) { |
| 7 | +export function getImports (source: string, options: Options) { |
5 | 8 | const { components, directives } = parseTemplate(source)
|
6 | 9 | const resolvedComponents: TemplateMatch[] = []
|
7 | 10 | const resolvedDirectives: TemplateMatch[] = []
|
8 | 11 | const imports = new Map<string, string[]>()
|
| 12 | + const ignore = (isObject(options.autoImport) && options.autoImport.ignore) || null |
| 13 | + const includeLabs = isObject(options.autoImport) && options.autoImport.labs |
| 14 | + const map = includeLabs |
| 15 | + ? { |
| 16 | + components: { ...importMap.components, ...importMapLabs.components }, |
| 17 | + directives: importMap.directives, |
| 18 | + } |
| 19 | + : importMap |
9 | 20 |
|
10 | 21 | if (components.size || directives.size) {
|
11 | 22 | components.forEach(component => {
|
12 |
| - if (component.name in importMap.components && !ignore.includes(component.name)) { |
| 23 | + if (ignore?.includes(component.name as any)) return |
| 24 | + if (component.name in importMap.components) { |
| 25 | + resolvedComponents.push(component) |
| 26 | + } else if (includeLabs && component.name in importMapLabs.components) { |
13 | 27 | resolvedComponents.push(component)
|
14 | 28 | }
|
15 | 29 | })
|
16 | 30 | directives.forEach(directive => {
|
17 |
| - if (importMap.directives.includes(directive.name) && !ignore.includes(directive.name)) { |
| 31 | + if (importMap.directives.includes(directive.name) && !ignore?.includes(directive.name as any)) { |
18 | 32 | resolvedDirectives.push(directive)
|
19 | 33 | }
|
20 | 34 | })
|
21 | 35 | }
|
22 | 36 |
|
23 | 37 | resolvedComponents.forEach(component => {
|
24 |
| - addImport(imports, component.name, component.symbol, 'vuetify/lib/' + (importMap.components as any)[component.name].from) |
| 38 | + addImport(imports, component.name, component.symbol, 'vuetify/lib/' + (map.components as any)[component.name].from) |
25 | 39 | })
|
26 | 40 | resolvedDirectives.forEach(directive => {
|
27 | 41 | addImport(imports, directive.name, directive.symbol, 'vuetify/lib/directives/index.mjs')
|
|
0 commit comments