Skip to content

Commit 44adb18

Browse files
committed
feat: compatible with the original additionalData
1 parent 9133761 commit 44adb18

3 files changed

Lines changed: 29 additions & 10 deletions

File tree

src/core/options.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useNuxt } from '@nuxt/kit'
22
import { libraryName, optimizeDeps } from '../config'
33
import type { ModuleOptions, Themes } from '../types'
4+
import { isFunction } from '../utils'
45

56
export function resolveOptions (config: ModuleOptions) {
67
const { cache, importStyle, namespace, themeChalk } = config
@@ -18,11 +19,17 @@ export function resolveOptions (config: ModuleOptions) {
1819
nuxt.options.vite.optimizeDeps.exclude.push(libraryName)
1920
}
2021

22+
nuxt.options.vite.css ||= {}
23+
nuxt.options.vite.css.preprocessorOptions ||= {}
24+
nuxt.options.vite.css.preprocessorOptions.scss ||= {}
25+
nuxt.options.vite.css.preprocessorOptions.scss.api = 'modern-compiler'
26+
nuxt.options.webpack.loaders.scss.api = 'modern-compiler'
27+
2128
if (importStyle === 'scss' && themeChalk) {
2229
const keys = Object.keys(themeChalk)
2330
const files: Array<'namespace' | 'common' | Themes> = []
2431

25-
if (namespace) {
32+
if (namespace && namespace !== 'el') {
2633
files.push('namespace')
2734
}
2835
if (keys.some(key => key.startsWith('$'))) {
@@ -35,13 +42,21 @@ export function resolveOptions (config: ModuleOptions) {
3542
return all
3643
}, '')
3744

38-
nuxt.options.vite.css ||= {}
39-
nuxt.options.vite.css.preprocessorOptions ||= {}
40-
nuxt.options.vite.css.preprocessorOptions.scss ||= {}
41-
nuxt.options.vite.css.preprocessorOptions.scss.api = 'modern-compiler'
42-
nuxt.options.vite.css.preprocessorOptions.scss.additionalData = additionalData
45+
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
48+
}
49+
50+
if (additionalData) {
51+
const oldVite = nuxt.options.vite.css!.preprocessorOptions!.scss.additionalData
52+
nuxt.options.vite.css.preprocessorOptions.scss.additionalData = (source: string, ...arg: unknown[]) => {
53+
return genAdditionalData(oldVite, source, ...arg)
54+
}
4355

44-
nuxt.options.webpack.loaders.scss.api = 'modern-compiler'
45-
nuxt.options.webpack.loaders.scss.additionalData = additionalData
56+
const oldWebpack = nuxt.options.webpack.loaders.scss.additionalData
57+
nuxt.options.webpack.loaders.scss.additionalData = (source: string, ...arg: unknown[]) => {
58+
return genAdditionalData(oldWebpack, source, ...arg)
59+
}
60+
}
4661
}
4762
}

src/core/themeChalk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function resolveThemeChalk (config: ModuleOptions) {
2020
}
2121
})
2222

23-
if (namespace) {
23+
if (namespace && namespace !== 'el') {
2424
files.push(genNamespaceFile())
2525
}
2626

src/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ export function getLayersDir (layers: NuxtConfigLayer[]) {
3131
}
3232

3333
export function isObject (value: any): value is Record<string, any> {
34-
return typeof value === 'object' && value !== null && !Array.isArray(value)
34+
return typeof value === 'object' && value !== null && !isArray(value)
35+
}
36+
37+
export function isFunction (value: any): value is Function {
38+
return typeof value === 'function'
3539
}
3640

3741
export function isArray (value: any): value is any[] {

0 commit comments

Comments
 (0)