1 Star 2 Fork 0

Layoomiety/vite-vue3-template

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
unocss.config.ts 2.59 KB
一键复制 编辑 原始数据 按行查看 历史
Layoomiety 提交于 2022-11-07 11:24 +08:00 . feat: custom icons
import { presetAttributify, presetUno, transformerDirectives } from "unocss";
import presetIcons from "@unocss/preset-icons";
import { compareColors, stringToColor } from "@iconify/utils/lib/colors";
import {
importDirectory,
parseColors,
runSVGO,
deOptimisePaths
} from "@iconify/tools";
export default {
safelist: [],
presets: [
presetAttributify({
/* preset options */
prefix: "w:",
prefixedOnly: false,
ignoreAttributes: []
}),
presetUno(),
presetIcons({
prefix: "i-",
extraProperties: {
display: "inline-block",
"vertical-align": "middle"
},
collections: {
custom: async () => {
// Load icons
const iconSet = await importDirectory("src/assets/icons", {
prefix: "custom"
});
// Clean up each icon
await iconSet.forEach(async name => {
const svg = iconSet.toSVG(name)!;
// Change color to `currentColor`
const blackColor = stringToColor("black")!;
await parseColors(svg, {
defaultColor: "currentColor",
callback: (attr, colorStr, color) => {
// console.log('Color:', colorStr, color);
// Change black to 'currentColor'
if (color && compareColors(color, blackColor)) {
return "currentColor";
}
switch (color?.type) {
case "none":
case "current":
return color;
}
throw new Error(
`Unexpected color "${colorStr}" in attribute ${attr}`
);
}
});
// Optimise
runSVGO(svg);
// Update paths for compatibility with old software
await deOptimisePaths(svg);
// Update icon in icon set
iconSet.fromSVG(name, svg);
});
// Export as IconifyJSON
return iconSet.export();
}
}
})
],
shortcuts: {
"wh-full": "w-full h-full",
"wh-screen": "w-screen h-screen",
"flex-ac": "flex justify-around items-center",
"flex-bc": "flex justify-between items-center",
"flex-cc": "flex justify-center items-center",
"flex-sc": "flex justify-start items-center",
"flex-ec": "flex justify-end items-center",
"abso-lt": "absolute left-0 top-0",
"abso-rt": "absolute right-0 top-0",
"abso-lb": "absolute left-0 bottom-0",
"abso-rb": "absolute right-0 bottom-0"
},
rules: [],
transformers: [transformerDirectives()]
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/zouchengxin/vite-vue3-template.git
git@gitee.com:zouchengxin/vite-vue3-template.git
zouchengxin
vite-vue3-template
vite-vue3-template
web

搜索帮助