Skip to content

Commit 77bcd9c

Browse files
committed
docs: included instructions on how to use it with frameworks
Added instructions for vue and react
1 parent dbe8e7e commit 77bcd9c

1 file changed

Lines changed: 61 additions & 2 deletions

File tree

README.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,79 @@ background-repeat: no-repeat;
6262

6363
Which means that the flag is just going to appear in the middle of an element, so you will have to set manually the correct size of 4 by 3 ratio or if it's squared add also the `flag-icon-squared` class.
6464

65+
### Framework Usage
66+
67+
**Vite**
68+
69+
Add these plugins for Vite so the svg's can be treated as components
70+
71+
```js
72+
npm install --save-dev vite-plugin-svgr@4 @svgr/plugin-svgo @svgr/plugin-jsx
73+
```
74+
75+
Add this to your Vite config.
76+
77+
```js
78+
export default defineConfig({
79+
vite: {
80+
plugins: [
81+
svgr({
82+
include: "**/*.svg?react",
83+
svgrOptions: {
84+
plugins: ["@svgr/plugin-svgo", "@svgr/plugin-jsx"],
85+
svgoConfig: {
86+
plugins: [
87+
"preset-default",
88+
"removeTitle",
89+
"removeDesc",
90+
"removeDoctype",
91+
"cleanupIds",
92+
],
93+
},
94+
},
95+
}),
96+
],
97+
},
98+
});
99+
```
100+
101+
**React**
102+
103+
```js
104+
// SomeReactComponent.tsx
105+
import FlagEN from "flag-icons/svg/4x3/gb.svg?react";
106+
```
107+
108+
**Vue**
109+
110+
```vue
111+
// SomeReactComponent.vue
112+
<script setup>
113+
import FlagEN from "flag-icons/svg/4x3/gb.svg?vue";
114+
</script>
115+
<template>
116+
<FlagEN />
117+
</template>
118+
```
119+
120+
Thanks to Doray for the great article.
121+
122+
Link: [https://doray.me/articles/use-svgs-as-react-components-in-astro-MNUvh/](https://doray.me/articles/use-svgs-as-react-components-in-astro-MNUvh/)
123+
65124
## Development
66125

67126
Run the `yarn` to install the dependencies after cloning the project and you'll be able to:
68127

69128
To build `*.scss` files
70129

71130
```bash
72-
$ yarn build
131+
yarn build
73132
```
74133

75134
To serve it on `localhost:8000`
76135

77136
```bash
78-
$ yarn start
137+
yarn start
79138
```
80139

81140
To have only specific countries in the css file, remove the ones that you don't need from the [`_flag-icons-list.scss`](sass/_flag-icons-list.scss) file and build it again.

0 commit comments

Comments
 (0)