Skip to content

Commit

Permalink
fix: should resolve icons from all roots (#1838)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <github@antfu.me>
  • Loading branch information
KermanX and antfu committed Aug 26, 2024
1 parent e8d802c commit 9eeccbd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
15 changes: 1 addition & 14 deletions packages/client/uno.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { fileURLToPath } from 'node:url'
import { readFileSync } from 'node:fs'
import {
defineConfig,
presetAttributify,
presetIcons,
presetTypography,
presetUno,
transformerDirectives,
Expand Down Expand Up @@ -41,18 +38,8 @@ export default defineConfig({
presets: [
presetUno(),
presetAttributify(),
presetIcons({
collectionsNodeResolvePath: fileURLToPath(import.meta.url),
collections: {
slidev: {
logo: async () => {
const content = readFileSync(fileURLToPath(new URL('assets/logo.svg', import.meta.url)), 'utf-8')
return content
},
},
},
}),
presetTypography(),
/* Preset Icons is added in ../node/setups/unocss.ts */
],
transformers: [
transformerDirectives({ enforce: 'pre' }),
Expand Down
1 change: 1 addition & 0 deletions packages/slidev/node/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export async function createDataUtils(resolved: Omit<ResolvedSlidevOptions, 'uti
return {
...await setupShiki(resolved.roots),
indexHtml: setupIndexHtml(resolved),
iconsResolvePath: [resolved.clientRoot, ...resolved.roots].reverse(),
isMonacoTypesIgnored: pkg => monacoTypesIgnorePackagesMatches.some(i => i(pkg)),
getLayouts: () => {
const now = Date.now()
Expand Down
18 changes: 15 additions & 3 deletions packages/slidev/node/setups/unocss.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { resolve } from 'node:path'
import { existsSync } from 'node:fs'
import { existsSync, readFileSync } from 'node:fs'
import type { Theme } from '@unocss/preset-uno'
import type { UserConfig } from '@unocss/core'
import { mergeConfigs } from 'unocss'
import { mergeConfigs, presetIcons } from 'unocss'
import type { ResolvedSlidevOptions, UnoSetup } from '@slidev/types'
import { loadSetups } from '../setups/load'
import { loadModule } from '../utils'

export default async function setupUnocss(
{ clientRoot, roots, data }: ResolvedSlidevOptions,
{ clientRoot, roots, data, utils }: ResolvedSlidevOptions,
) {
function loadFileConfigs(root: string): UserConfig<Theme>[] {
return [
Expand All @@ -23,6 +23,18 @@ export default async function setupUnocss(
}

const configs = [
{
presets: [
presetIcons({
collectionsNodeResolvePath: utils.iconsResolvePath,
collections: {
slidev: {
logo: () => readFileSync(resolve(clientRoot, 'assets/logo.svg'), 'utf-8'),
},
},
}),
],
},
...loadFileConfigs(clientRoot),
...await loadSetups<UnoSetup>(roots, 'unocss.ts', [], loadFileConfigs),
].filter(Boolean) as UserConfig<Theme>[]
Expand Down
5 changes: 2 additions & 3 deletions packages/slidev/node/vite/icons.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { fileURLToPath } from 'node:url'
import type { ResolvedSlidevOptions, SlidevPluginOptions } from '@slidev/types'
import Icons from 'unplugin-icons/vite'

export function createIconsPlugin(
_options: ResolvedSlidevOptions,
options: ResolvedSlidevOptions,
pluginOptions: SlidevPluginOptions,
) {
return Icons({
defaultClass: 'slidev-icon',
collectionsNodeResolvePath: fileURLToPath(import.meta.url),
collectionsNodeResolvePath: options.utils.iconsResolvePath,
...pluginOptions.icons,
})
}
1 change: 1 addition & 0 deletions packages/types/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface ResolvedSlidevUtils {
shiki: HighlighterGeneric<any, any>
shikiOptions: MarkdownItShikiOptions
indexHtml: string
iconsResolvePath: string[]
isMonacoTypesIgnored: (pkg: string) => boolean
getLayouts: () => Record<string, string>
}
Expand Down

0 comments on commit 9eeccbd

Please sign in to comment.