32 lines
952 B
TypeScript
32 lines
952 B
TypeScript
import path from 'node:path'
|
|
import process from 'node:process'
|
|
import { FileSystemIconLoader } from '@iconify/utils/lib/loader/node-loaders'
|
|
import presetIcons from '@unocss/preset-icons'
|
|
import unocss from '@unocss/vite'
|
|
|
|
export function setupUnocss(viteEnv: Env.ImportMeta) {
|
|
const { VITE_ICON_PREFIX, VITE_ICON_LOCAL_PREFIX } = viteEnv
|
|
|
|
const localIconPath = path.join(process.cwd(), 'src/assets/svg-icon')
|
|
|
|
/** The name of the local icon collection */
|
|
const collectionName = VITE_ICON_LOCAL_PREFIX.replace(`${VITE_ICON_PREFIX}-`, '')
|
|
|
|
return unocss({
|
|
presets: [
|
|
presetIcons({
|
|
prefix: `${VITE_ICON_PREFIX}-`,
|
|
scale: 1,
|
|
extraProperties: {
|
|
display: 'inline-block',
|
|
},
|
|
collections: {
|
|
[collectionName]: FileSystemIconLoader(localIconPath, svg =>
|
|
svg.replace(/^<svg\s/, '<svg width="1em" height="1em" ')),
|
|
},
|
|
warn: true,
|
|
}),
|
|
],
|
|
})
|
|
}
|