Skip to content

Commit

Permalink
fix(nuxt): avoid preset duplication, close #1054
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jun 4, 2022
1 parent 2c9627e commit 91b2f08
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Expand Up @@ -545,6 +545,7 @@ export interface ResolvedConfig extends Omit<
RequiredByKey<UserConfig, 'mergeSelectors' | 'theme' | 'rules' | 'variants' | 'layers' | 'extractors' | 'blocklist' | 'safelist' | 'preflights' | 'sortLayers'>,
'rules' | 'shortcuts' | 'autocomplete'
> {
presets: Preset[]
shortcuts: Shortcut[]
variants: VariantObject[]
preprocess: Preprocessor[]
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxt/src/index.ts
Expand Up @@ -55,12 +55,12 @@ export default defineNuxtModule<UnocssNuxtOptions>({

extendViteConfig((config) => {
config.plugins = config.plugins || []
config.plugins.unshift(...VitePlugin(options))
config.plugins.unshift(...VitePlugin({}, options))
})

extendWebpackConfig((config) => {
config.plugins = config.plugins || []
config.plugins.unshift(WebpackPlugin(options))
config.plugins.unshift(WebpackPlugin({}, options))
})
},
})
Expand Down
11 changes: 11 additions & 0 deletions packages/shared-integration/src/context.ts
Expand Up @@ -39,6 +39,17 @@ export function createContext<Config extends UserConfig<any> = UserConfig<any>>(
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)))
invalidate()

// check preset duplication
const presets = new Set<string>()
uno.config.presets.forEach((i) => {
if (!i.name)
return
if (presets.has(i.name))
console.warn(`[unocss] duplication of preset ${i.name} found, there might be something wrong with your config.`)
else
presets.add(i.name)
})

return result
}

Expand Down

0 comments on commit 91b2f08

Please sign in to comment.