Skip to content

Commit 0392bbc

Browse files
committed
feat: added unpluginIconViteOptions helper for more easily configuring unplugin icons
1 parent d7d6f0a commit 0392bbc

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed

README.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Everything can just be done from the config. Nuxt will automatically import the
2323
You can also configure which directives the vue plugin auto-imports with the witchcraftComponents key (the lib will soon be renamed).
2424

2525
```ts
26+
import { unpluginIconViteOptions } from "@alanscodelog/vue-components/helpers/unpluginIconViteOptions.js"
27+
//...
2628
modules: [
2729
[
2830
"@alanscodelog/vue-components/nuxt",
@@ -39,10 +41,25 @@ You can also configure which directives the vue plugin auto-imports with the wit
3941
defineModel: true,
4042
},
4143
}
44+
plugins: [
45+
Components({
46+
resolvers: [
47+
IconsResolver({}),
48+
],
49+
}),
50+
// https://github.com/unplugin/unplugin-icons#custom-icons
51+
// these opts can be imported from "@alanscodelog/vue-components/helpers/unpluginIconViteOptions.js"
52+
// changes the default styling slightly
53+
Icons(unpluginIconViteOptions),
54+
]
4255
}
43-
4456
```
4557

58+
## Icons
59+
60+
This library uses unplugin-icons to provide icons. You will need to install `@iconify/json` or install the used icon packs (various are used, depending on the component).
61+
62+
4663
# Usage with Vite
4764

4865
In `main.ts` or where vue is mounted:
@@ -62,15 +79,11 @@ createApp(App)
6279
.use(VueComponentsPlugin) //use plugin
6380

6481
```
65-
In the vite config, vue will require the experimental defineModel:
82+
In the vite config, vue will require the experimental defineModel and the unplugin icons config:
6683

6784
```
6885
plugins: [
69-
vue({
70-
script: {
71-
defineModel: true,
72-
},
73-
}),
86+
// see nuxt's vite config above
7487
],
7588
```
7689

src/helpers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export { NotificationHandler } from "./NotificationHandler.js"
99
export { readFile } from "./readFile.js"
1010
export { ResizeObserverWrapper } from "./resizeObserverWrapper.js"
1111
export { twMerge } from "./twMerge.js"
12+
export { unpluginIconViteOptions } from "./unpluginIconViteOptions.js"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type Icons from "unplugin-icons/vite"
2+
3+
// @ts-expect-error not sure why only failing with lint
4+
export const unpluginIconViteOptions: Parameters<typeof Icons>[0] = {
5+
scale: 0, // removes the scale
6+
// @ts-expect-error .
7+
iconCustomizer: async (_, __, props) => {
8+
props.width = "unset"
9+
},
10+
// note that we can't use tailwind classes
11+
// i mean we could, but we have to tell it to include them manually (pain)
12+
defaultStyle: "vertical-align: -0.125em; height: 1em; display: inline-block; width:auto;",
13+
}

vite.config.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { externalizeDeps } from "vite-plugin-externalize-deps"
1212

1313
// @ts-expect-error .
1414
import postcss from "./postcss.config.js"
15+
import { unpluginIconViteOptions } from "./src/helpers/unpluginIconViteOptions.js"
1516

1617

1718
const folders = fs.readdirSync("src", { withFileTypes: true })
@@ -48,14 +49,7 @@ export default async ({ mode }: { mode: string }) => defineConfig({
4849
}),
4950
],
5051
}),
51-
Icons({
52-
// makes this work like fontawesome
53-
scale: 0, // removes the scale
54-
defaultClass: "icon",
55-
// note that we can't use tailwind classes
56-
// i mean we could, but we have to tell it to include them manually (pain)
57-
defaultStyle: "vertical-align: -0.125em; height: 1em; display: inline-block;",
58-
})
52+
Icons(unpluginIconViteOptions)
5953
],
6054
build: {
6155
outDir: "dist",

0 commit comments

Comments
 (0)