Skip to content

Commit 947b11b

Browse files
committed
chore: add fontawesome to the project
1 parent 005e145 commit 947b11b

File tree

6 files changed

+256
-10
lines changed

6 files changed

+256
-10
lines changed

README.md

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,69 @@ You can now update imports:
588588
589589
> Furthermore, don't add the `output.clean` option in webpack configuration, it will prevent React components from hot reloading. For more information, take a look at the [issue](https://github.com/pmmmwh/react-refresh-webpack-plugin/issues/595) I opened on the connector plugin repository.
590590
591-
## Testing with Jest
591+
## Use FontAwesome icons
592+
593+
There are a few ways to add FontAwesome to a project. The following is the best way as only the icons used will be included in the build.
594+
595+
- add fontawesome svg core
596+
597+
```sh
598+
npm i --save @fortawesome/fontawesome-svg-core
599+
```
600+
601+
- install icon styles you need
602+
603+
```sh
604+
npm i --save @fortawesome/free-solid-svg-icons
605+
# npm i --save @fortawesome/free-brands-svg-icons
606+
# npm i --save @fortawesome/free-regular-svg-icons
607+
```
608+
609+
- install FontAwesome React component
610+
611+
```sh
612+
npm i --save @fortawesome/react-fontawesome@latest
613+
```
614+
615+
- install Babel macros
616+
617+
```sh
618+
npm install --save-dev babel-plugin-macros
619+
```
620+
621+
- add the plugin to Babel config file
622+
623+
```js
624+
plugins: [
625+
'@babel/plugin-transform-runtime',
626+
'macros',
627+
!(api.env('production') || api.env('test')) && 'react-refresh/babel',
628+
].filter(Boolean),
629+
```
630+
631+
- create babel-plugin-macros.config.js and add the fontawesome-svg-core settings
632+
633+
```js
634+
module.exports = {
635+
"fontawesome-svg-core": {
636+
license: "free",
637+
},
638+
};
639+
```
640+
641+
- add icons to react component
642+
643+
```jsx
644+
// top of the file
645+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
646+
import { solid } from '@fortawesome/fontawesome-svg-core/import.macro'
647+
648+
// use icons
649+
<FontAwesomeIcon icon={solid('plus')} size="sm" />
650+
<FontAwesomeIcon icon={solid('minus')} size="sm" />
651+
```
652+
653+
## Test your app with Jest
592654

593655
- create Jest file configuration
594656

@@ -707,7 +769,7 @@ You can now update imports:
707769
npm test
708770
```
709771

710-
## Linter (ESLint)
772+
## Lint your code with ESLint
711773

712774
> We choose [Airbnb rules preset](https://github.com/airbnb/javascript) for our project
713775

@@ -780,7 +842,7 @@ You can now update imports:
780842

781843
> You can download the ESLint plugin of your favorite IDE [here](https://eslint.org/docs/user-guide/integrations#editors), so that you don't have to run the lint script every time.
782844

783-
## Formatter (Prettier)
845+
## Format your code with Prettier
784846

785847
### No [integration with ESLint](https://prettier.io/docs/en/integrating-with-linters) wanted. Why ?
786848

@@ -956,4 +1018,5 @@ We have to build the app and push the content of the build directory to a new br
9561018
- [Prevent missing React when using JSX](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md)
9571019
- [Utiliser ESLint et Prettier pour un code de qualité](https://jeremiechazelle.dev/utiliser-eslint-et-prettier-sous-visual-studio-code-webstorm-phpstorm-pour-un-code-de-qualite)
9581020
- [How to setup ESLint and Prettier for your React apps](https://thomaslombart.com/setup-eslint-prettier-react)
959-
- [How do I force git to use LF instead of CR+LF?](https://stackoverflow.com/a/42136008/16072226)
1021+
- [How do I force git to use LF instead of CR+LF?](https://stackoverflow.com/a/42136008/16072226)
1022+
- [Set Up FontAwesome with React](https://fontawesome.com/docs/web/use-with/react)

babel-plugin-macros.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
'fontawesome-svg-core': {
3+
license: 'free',
4+
},
5+
};

babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = (api) => {
1111
],
1212
plugins: [
1313
'@babel/plugin-transform-runtime',
14+
'macros',
1415
!(api.env('production') || api.env('test')) && 'react-refresh/babel',
1516
].filter(Boolean),
1617
};

package-lock.json

Lines changed: 162 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)