u
This commit is contained in:
1 parent
7dd7794fd1
commit
9b2db64cc6
10 files changed
+160
-5
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import path from "node:path";
|
||||
import process from "node:process";
|
||||
import { FileSystemIconLoader } from "unplugin-icons/loaders";
|
||||
import type { PluginOption } from "vite";
|
||||
import Icons from "unplugin-icons/vite";
|
||||
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
|
||||
export function setupUnPluginIcon(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}-`,
|
||||
""
|
||||
);
|
||||
|
||||
const plugins: PluginOption[] = [
|
||||
createSvgIconsPlugin({
|
||||
iconDirs: [localIconPath],
|
||||
symbolId: `${VITE_ICON_LOCAL_PREFIX}-[dir]-[name]`,
|
||||
inject: "body-last",
|
||||
customDomId: "__SVG_ICON_LOCAL__",
|
||||
}),
|
||||
Icons({
|
||||
compiler: "vue3",
|
||||
customCollections: {
|
||||
[collectionName]: FileSystemIconLoader(localIconPath, (svg) =>
|
||||
svg.replace(/^<svg\s/, '<svg width="1em" height="1em" ')
|
||||
),
|
||||
},
|
||||
scale: 1,
|
||||
defaultClass: "inline-block",
|
||||
}),
|
||||
];
|
||||
|
||||
return plugins;
|
||||
}
|
||||
Reference in new issue
Block a user