11import { useNuxt } from '@nuxt/kit'
22import { libraryName , optimizeDeps } from '../config'
3- import type { ModuleOptions , Themes } from '../types'
43import { isFunction } from '../utils'
4+ import type { ModuleOptions , Themes } from '../types'
55
66export function resolveOptions ( config : ModuleOptions ) {
77 const { cache, importStyle, namespace, themeChalk } = config
@@ -26,25 +26,28 @@ export function resolveOptions (config: ModuleOptions) {
2626 nuxt . options . webpack . loaders . scss . api ??= 'modern-compiler'
2727
2828 if ( importStyle === 'scss' && themeChalk ) {
29- const keys = Object . keys ( themeChalk )
3029 const files : Array < 'namespace' | 'common' | Themes > = [ ]
30+ const keys = Object . keys ( themeChalk ) as ( keyof typeof themeChalk ) [ ]
31+ const themes = keys . filter ( ( key ) => {
32+ return ! key . startsWith ( '$' ) && themeChalk [ key ] && Object . keys ( themeChalk [ key ] ) . length
33+ } ) as Themes [ ]
3134
3235 if ( namespace && namespace !== 'el' ) {
3336 files . push ( 'namespace' )
3437 }
3538 if ( keys . some ( key => key . startsWith ( '$' ) ) ) {
3639 files . push ( 'common' )
3740 }
38- files . push ( ...keys . filter ( key => ! key . startsWith ( '$' ) ) as Themes [ ] )
41+ files . push ( ...themes )
3942
4043 const additionalData = files . reduce ( ( all , item ) => {
4144 all += `@use "${ nuxt . options . buildDir } /${ libraryName } -scss-${ item } .scss";`
4245 return all
4346 } , '' )
4447
4548 async function genAdditionalData ( old : string | Function | undefined , source : string , ...arg : unknown [ ] ) {
46- const res = isFunction ( old ) ? await old ( source , ...arg ) : ( old ?? '' ) + source
47- return additionalData + res
49+ const content = isFunction ( old ) ? await old ( source , ...arg ) : ( old ?? '' ) + source
50+ return additionalData + content
4851 }
4952
5053 if ( additionalData ) {
0 commit comments