Skip to content

Commit

Permalink
chore: include nuxt configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Apr 20, 2024
1 parent 1290478 commit 5904595
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/nuxt/src/index.ts
Expand Up @@ -36,7 +36,7 @@ export default defineNuxtModule<UnocssNuxtOptions>({
},
async setup(options, nuxt) {
// preset shortcuts
resolveOptions(options)
resolveOptions(nuxt, options)

options.mode ??= 'global'
const InjectModes: VitePluginConfig['mode'][] = ['global', 'dist-chunk']
Expand Down
16 changes: 15 additions & 1 deletion packages/nuxt/src/options.ts
Expand Up @@ -5,10 +5,12 @@ import presetWebFonts from '@unocss/preset-web-fonts'
import presetTypography from '@unocss/preset-typography'
import presetTagify from '@unocss/preset-tagify'
import presetWind from '@unocss/preset-wind'
import type { Preset } from '@unocss/core'
import type { Nuxt } from '@nuxt/schema'
import { defaultPipelineExclude } from '../../shared-integration/src/defaults'
import type { UnocssNuxtOptions } from './types'

export function resolveOptions(options: UnocssNuxtOptions) {
export function resolveOptions(nuxt: Nuxt, options: UnocssNuxtOptions) {
if (options.presets == null) {
options.presets = []
const presetMap = {
Expand All @@ -27,6 +29,13 @@ export function resolveOptions(options: UnocssNuxtOptions) {
}
}

const webFontPreset = lookupPreset(options, '@unocss/preset-web-fonts')
if (webFontPreset && !!webFontPreset.options?.downloadLocally) {
webFontPreset.options.downloadLocally = {}
webFontPreset.options.downloadLocally.downloadDir = `${nuxt.options.dir.public}/unocss-fonts`
webFontPreset.options.downloadLocally.downloadBasePath = nuxt.options.app.baseURL
}

options.content ??= {}
options.content.pipeline ??= {}
if (options.content.pipeline !== false) {
Expand All @@ -36,3 +45,8 @@ export function resolveOptions(options: UnocssNuxtOptions) {
options.content.pipeline.exclude.push(/\?macro=true/)
}
}

function lookupPreset<P extends Preset<any>>(options: UnocssNuxtOptions, presetName: P['name']) {
const preset: P | undefined = (options.presets || []).flat().find(p => p.name === presetName) as any
return preset
}

0 comments on commit 5904595

Please sign in to comment.