| 123456789101112131415161718192021222324252627282930313233 |
- import path from 'node:path';
- import process from 'node:process';
- import presetIcons from '@unocss/preset-icons';
- import unocss from '@unocss/vite';
- import { FileSystemIconLoader } from 'unplugin-icons/loaders';
- export function setupUnocss(viteEnv: Env.ImportMeta) {
- const { VITE_ICON_PREFIX = 'icon', VITE_ICON_LOCAL_PREFIX = 'local-icon' } = 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,
- }),
- ],
- });
- }
|