MCPcopy
hub / github.com/nuxt-modules/tailwindcss / resolveConfigs

Function resolveConfigs

src/internal-context/load.ts:25–62  ·  view source on GitHub ↗
(configs: T | T[], nuxt = useNuxt())

Source from the content-addressed store, hash-verified

23 const trackObjChanges = createObjProxy(configUpdatedHook, meta)
24
25 const resolveConfigs = <T extends Partial<TWConfig> | string | undefined>(configs: T | T[], nuxt = useNuxt()) =>
26 ((Array.isArray(configs) ? configs : [configs])
27 .filter((c): c is NonNullable<T> => Boolean(c) && c !== join(nuxt.options.rootDir, 'tailwind.config'))
28 .map(async (config, idx, arr): Promise<ResolvedConfig | null> => {
29 if (typeof config !== 'string') {
30 const hasUnsafeProperty = checkUnsafeInlineConfig(config)
31 if (hasUnsafeProperty && !meta.disableHMR) {
32 logger.warn(
33 `The provided Tailwind configuration in your \`nuxt.config\` is non-serializable. Check \`${hasUnsafeProperty}\`. Falling back to providing the loaded configuration inlined directly to PostCSS loader..`,
34 'Please consider using `tailwind.config` or a separate file (specifying in `configPath` of the module options) to enable it with additional support for IntelliSense and HMR. Suppress this warning with `quiet: true` in the module options.',
35 )
36 meta.disableHMR = true
37 twCtx.set({ meta })
38 }
39
40 return { config } as { config: NonNullable<T> }
41 }
42
43 const configFile = await (config.startsWith(nuxt.options.buildDir) ? config : findPath(config, { extensions: ['.js', '.cjs', '.mjs', '.ts'] }))
44 return configFile
45 ? loadConfig({ configFile }).then(async (resolvedConfig) => {
46 const { configFile: resolvedConfigFile = configFile } = resolvedConfig
47 const config = configMerger(undefined, resolvedConfig.config)
48 configUpdatedHook[resolvedConfigFile] = ''
49
50 if (resolvedConfig.config?.purge && !resolvedConfig.config.content) {
51 configUpdatedHook[resolvedConfigFile] += 'cfg.content = cfg.purge;'
52 }
53
54 await nuxt.callHook('tailwindcss:loadConfig', config, resolvedConfigFile, idx, arr as any)
55 trackObjChanges(resolvedConfigFile, resolvedConfig.config, config)
56 return { ...resolvedConfig, config }
57 }).catch((e) => {
58 logger.warn(`Failed to load config \`./${relative(nuxt.options.rootDir, configFile)}\` due to the error below. Skipping..\n`, e)
59 return null
60 })
61 : null
62 }))
63
64 const resolveContentConfig = (rootDir: string, nuxtOptions: NuxtOptions | NuxtConfig = useNuxt().options): ResolvedConfig => {
65 const r = (p: string) => isAbsolute(p) || p.startsWith(rootDir) ? p : resolve(rootDir, p)

Callers 1

getModuleConfigsFunction · 0.85

Calls 1

checkUnsafeInlineConfigFunction · 0.90

Tested by

no test coverage detected