|
1 | 1 | import type { Nuxt } from '@nuxt/schema' |
2 | 2 | import defu from 'defu' |
3 | | -import type { InlineModuleOptions, VuetifyModuleOptions } from '../types' |
| 3 | +import type { FontIconSet, IconFontName, InlineModuleOptions, VuetifyModuleOptions } from '../types' |
4 | 4 | import { loadVuetifyConfiguration } from './config' |
5 | 5 |
|
6 | 6 | /** |
@@ -54,19 +54,52 @@ export async function mergeVuetifyModules(options: VuetifyModuleOptions, nuxt: N |
54 | 54 | }) |
55 | 55 |
|
56 | 56 | if (moduleOptions.length > 1) { |
57 | | - const [base, ...rest] = moduleOptions |
| 57 | + // reverse to allow override configuration from app: fix #218 |
| 58 | + const [base, ...rest] = moduleOptions.reverse() |
| 59 | + // modules are reversed, so the last one has the highest priority (app) |
| 60 | + const configuration = <InlineModuleOptions>defu(base, ...rest) |
| 61 | + // dedupe icons sets: fix #217 |
| 62 | + dedupeIcons(configuration, moduleOptions) |
58 | 63 | return { |
59 | | - configuration: <InlineModuleOptions>defu(base, ...rest), |
| 64 | + configuration, |
60 | 65 | vuetifyConfigurationFilesToWatch, |
61 | 66 | } |
62 | 67 | } |
63 | 68 | else { |
64 | 69 | return { |
65 | | - configuration: <InlineModuleOptions>{ |
| 70 | + configuration: { |
66 | 71 | moduleOptions: options.moduleOptions, |
67 | 72 | vuetifyOptions: resolvedOptions.config, |
68 | | - }, |
| 73 | + } satisfies InlineModuleOptions, |
69 | 74 | vuetifyConfigurationFilesToWatch, |
70 | 75 | } |
71 | 76 | } |
72 | 77 | } |
| 78 | + |
| 79 | +// dedupe icons sets: fix #217 |
| 80 | +function dedupeIcons(configuration: InlineModuleOptions, moduleOptions: InlineModuleOptions[]) { |
| 81 | + const vuetifyOptions = configuration.vuetifyOptions |
| 82 | + if (vuetifyOptions.icons) { |
| 83 | + if (vuetifyOptions.icons.sets) { |
| 84 | + const sets = new Map<string, FontIconSet>() |
| 85 | + // modules are reversed, so the last one has the highest priority (app) |
| 86 | + for (const { vuetifyOptions } of moduleOptions) { |
| 87 | + if (vuetifyOptions.icons && vuetifyOptions.icons.sets) { |
| 88 | + const mSets = vuetifyOptions.icons.sets |
| 89 | + if (typeof mSets === 'string') { |
| 90 | + sets.set(mSets, { name: mSets as IconFontName }) |
| 91 | + } |
| 92 | + else { |
| 93 | + for (const set of mSets) { |
| 94 | + if (typeof set === 'string') |
| 95 | + sets.set(set, { name: set as IconFontName }) |
| 96 | + else |
| 97 | + sets.set(set.name, set) |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + vuetifyOptions.icons.sets = Array.from(sets.values()) |
| 103 | + } |
| 104 | + } |
| 105 | +} |
0 commit comments