# fa-dynamic.macro

> This Macro wil automatically import fontawesome icon

Latest version **1.0.3** (published 2023-12-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install fa-dynamic.macro
pnpm add fa-dynamic.macro
yarn add fa-dynamic.macro
bun add fa-dynamic.macro
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2023-12-23 |
| First published | 2023-12-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | MD Abul Hossain |
| Maintainers | _hifromabul |
| Keywords | babel, babel-plugin, dynamic icon, babel-plugin-macros, font awesome dynamic |

## Links

- npm: https://www.npmjs.com/package/fa-dynamic.macro
- Repository: https://github.com/abul2285/fa-dynamic.macro
- Homepage: https://github.com/abul2285/fa-dynamic.macro#readme
- Issues: https://github.com/abul2285/fa-dynamic.macro/issues
- npm.io page: https://npm.io/package/fa-dynamic.macro

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2023-12-23
- 1.0.2 — 2023-12-22
- 1.0.1 — 2023-12-16
- 1.0.0 — 2023-12-16

## README

## Table of Contents

- [Babel Macro for Dynamic Font Awesome Icon Import](#babel-macro-for-dynamic-font-awesome-icon-import)

  - [Introduction](#introduction)
  - [Features](#features)
  - [Installation](#installation)
    - [Free Icons Styles](#free-icons-styles)
    - [Pro Icons Styles](#pro-icons-styles)
  - [Usage](#usage)
    - [Babel Plugin Macros Config](#babel-plugin-macros-config)
    - [Use Macro](#use-macro)
    - [Use Font Awesome Icon](#use-font-awesome-icon)
  - [Contact Information](#contact-information)

## Babel Macro for Dynamic Font Awesome Icon Import

### Introduction

This Babel macro automates the process of importing Font Awesome icons based on a provided configuration. No more manual imports; the macro scans the specified directory and imports icons automatically.

### Features

- Automatically imports icons from Font Awesome based on the given configuration.
- Supports importing icons from different Font Awesome packages (e.g., `solid`, `regular`, `light`, `thin`, `duotone` etc.).
- Scans a specified directory for icons and imports them automatically.

### Installation

To use this macro, install it in your project:

```bash
npm install --save-dev fa-dynamic.macro
```

#### Free icons styles

```bash
npm i --save @fortawesome/free-solid-svg-icons
npm i --save @fortawesome/free-regular-svg-icons
npm i --save @fortawesome/free-brands-svg-icons
```

#### Pro icons styles

Create an `.npmrc` file in your project root with the following content, replacing `FONT-AWESOME-PACKAGE-FONT-AWESOME-PACKAGE-FONT-AWESOME-PACKAGE-FONT-AWESOME-PACKAGE-TOKEN` with your actual Font Awesome package token:

```js
@fortawesome:registry=https://npm.fontawesome.com/
//npm.fontawesome.com/:_authToken=FONT-AWESOME-PACKAGE-FONT-AWESOME-PACKAGE-FONT-AWESOME-PACKAGE-FONT-AWESOME-PACKAGE-TOKEN
```

#### Then, install the pro icons styles

```bash
npm i --save @fortawesome/pro-solid-svg-icons
npm i --save @fortawesome/pro-regular-svg-icons
npm i --save @fortawesome/pro-light-svg-icons
npm i --save @fortawesome/pro-thin-svg-icons
npm i --save @fortawesome/pro-duotone-svg-icons
npm i --save @fortawesome/sharp-solid-svg-icons
npm i --save @fortawesome/sharp-regular-svg-icons
npm i --save @fortawesome/sharp-light-svg-icons
npm i --save @fortawesome/sharp-thin-svg-icons
```

### Usage

#### Babel Plugin Macros Config

Create a `babel-plugin-macros.config.js` file in your project root and configure the `fa-dynamic` settings. The configuration includes the following options:

- `path` (required): The relative path to the directory containing the icons.
- `license` (optional): You can set the license to either `free` or `pro` depending on the icons you are planning to use. The free version will be used by default.
- `matcher` (optional): This regex pattern will be used to match the icon. The default pattern will match `"far", "times"`, `'far', 'chevron-left'` patterns.

```js
// babel-plugin-macros.config.js

module.exports = {
  'fa-dynamic': {
    path: './src',
    license: 'pro',
    matcher: /['"]fa(?:s|r|b|t|l|d)['"],\s*["'](?:[a-z0-9]-?)+["']/gm,
  },
};
```

#### Use Macro

```js
// index.js

import importFaIcons from 'fa-dynamic.macro';
import App from './App';

importFaIcons();

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);
```

#### Use Font Awesome Icon

```js
// App.js

function App() {
  return (
    <div className='App'>
      <header className='App-header'>
        <FontAwesomeIcon icon={['far', 'calendar']} />
        <FontAwesomeIcon icon={['fas', 'times']} />
        <FontAwesomeIcon icon={['fal', 'chevron-right']} />
        <FontAwesomeIcon icon={['fat', 'backpack']} />
      </header>
    </div>
  );
}

export default App;
```

In this example, all icons inside the `src` directory will be automatically loaded, eliminating the need for manual importation. The license option determines whether to import icons from the free or pro version of Font Awesome.

## Contact Information

- **GitHub Username:** [abul2285](https://github.com/abul2285)
- **Email:** [mdabulhossain780@gmail.com](mailto:mdabulhossain780@gmail.com)
- **Portfolio Website:** [abul.dev](https://abul.dev)

---
_Source: https://npm.io/package/fa-dynamic.macro · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
