Skip to content

Configuration

The config is data, not code: YAML or JSON. It is a file named react-svg-icons.config.yaml, .yml or .json, or an rc file (.react-svg-iconsrc and its .yaml, .yml and .json variants), searched in the folder you run the command from in the order listed in CLI, or any file you pass with --config. YAML allows comments:

input: icons
outDir: generated

Relative paths are relative to the folder that holds the config file, not to where you run the command. An option the tool does not know, such as a typo, stops the build with a message that lists the valid names.


Option Type Default Meaning
input string required The folder with the exported SVGs
outDir string required The folder the components are written to
removeWords string[] [] Words dropped from every icon name
defaultSize number 24 The size of an icon when none is given
defaultStrokeWidth number 2 The strokeWidth of an icon whose SVG has none
format "prettier" or false "prettier" Format the output with the project’s prettier, or write it raw

outDir is created when it is missing. The tool only ever deletes a .ts or .tsx file that carries its own banner (auto-generated by @mrzr/react-svg-icons; the banner of version 0.1.0, without the scope, counts too) and that this run does not produce, which is what is left when an SVG is removed or renamed. A file of yours in outDir is never touched. outDir must not be the input folder or a folder that contains it.

Words that appear in your file names and must not be in the component name. A word is compared without regard to case, against each word of the file name:

removeWords: [ic, icon]

ic linear eye.svg in linear/ becomes Eye. How the whole name is made is in Naming.

defaultSize: 20
defaultStrokeWidth: 1.5

defaultSize is the default of the size prop of every icon and of Icon. defaultStrokeWidth is the default of strokeWidth for an SVG that has no stroke-width: an SVG that has one keeps it. Both must be positive numbers.

With "prettier" the output is formatted the way your own formatting would leave it, so --check still passes after a formatting run. The tool looks for prettier in the project (resolved from the config file’s folder), then next to itself, and uses the prettier config found from the config file’s folder. If prettier is not found it warns:

@mrzr/react-svg-icons: prettier is not installed, so the output is not formatted. Install it in the project, or set `format: false` to silence this.

and writes the raw text. format: false writes the raw text without the warning. The raw and the formatted text differ only in formatting.

Because --check compares text, the prettier version and its config are part of what is checked: formatting with another prettier or config makes --check report the files as changed.


The same options in react-svg-icons.config.json:

{
"input": "icons",
"outDir": "generated",
"removeWords": ["ic", "icon"]
}

Or in an rc file, .react-svg-iconsrc, which holds YAML or JSON.

@mrzr/react-svg-icons: `input` is required (or outDir) when one is missing. @mrzr/react-svg-icons: unknown option "<name>" (options: …) for a name it does not know. A number option that is not a positive number stops with @mrzr/react-svg-icons: `defaultSize` must be a positive number. See Troubleshooting for every message.