# tailwind-svg-import

> Import your file system svgs to Tailwind.

Latest version **0.4.0** (published 2020-09-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install tailwind-svg-import
pnpm add tailwind-svg-import
yarn add tailwind-svg-import
bun add tailwind-svg-import
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2020-09-08 |
| First published | 2020-09-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | J. Ryan Conklin @jryanconklin |
| Maintainers | jryanconklin |

## Links

- npm: https://www.npmjs.com/package/tailwind-svg-import
- Repository: https://github.com/jryanconklin/tailwind-svg-import
- Homepage: https://github.com/jryanconklin/tailwind-svg-import#readme
- Issues: https://github.com/jryanconklin/tailwind-svg-import/issues
- npm.io page: https://npm.io/package/tailwind-svg-import

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.20
- [mini-svg-data-uri](https://npm.io/package/mini-svg-data-uri.md) ^1.2.3

## Recent versions

- 0.4.0 (latest) — 2020-09-08
- 0.3.0 — 2020-09-04
- 0.2.0 — 2020-09-04
- 0.1.0 — 2020-09-04

## README

# Tailwind SVG Import

This project adds handling for file system SVGs into Tailwind content.

The goal of the project is to allow you to provide Tailwind a directory and add
those directly to utilities or components based on mode. It also optionally
allows for SVGs to be colorized with additional configuration.

## Install

1. Install the plugin:

```bash
# Using npm
npm install tailwind-svg-import --save-dev

# Using Yarn
yarn add tailwind-svg-import -D
```

2. Add it to your `tailwind.config.js` file:

```js
// tailwind.config.js
module.exports = {
  // ...
  plugins: [require('tailwind-svg-import')],
};
```

## Documentation

### User SVG Files

This plugin doesn't make any opinions about where your assets are stored in your
system. For this to work, the files must be available locally. It is recommended
you use a tool such as [SVGO](https://github.com/svg/svgo) to preconfigure your
SVG files. If you wish to use the `colorize` option, the SVG file must contain
`currentColor` on the SVG attribute you wish to colorize.

Note that this plugin operates by replacing that value with each value in the
`color` configuration. Sample SVGO config from
[@tailwindlabs/heroicons](https://github.com/tailwindlabs/heroicons):

```yaml
'plugins':
  - 'removeDimensions': true
  - 'removeXMLNS': false
  - 'sortAttrs': true
  - 'removeAttrs':
      attrs: 'fill'
  - 'addAttributesToSVGElement':
      attributes:
        - 'fill': 'currentColor'
```

### Options

All options are optional and will merge and overwrite default options.

- `colors`: Object. Define the colors you wish to use for colorize.
- `colorize`: Boolean. Optionally replace `currentColor` in your SVG with
  provided colors.
- `dirs`: Object. The file directories this plugin should scan.
- `mode`: String (all|vars|utils). Add CSS vars or SVGs, utility classes, or
  both.

#### Mode

The mode setting is used to decide how the plugin operates:

- vars: Create CSS Variables
- utils: Create `background-image` utility classes
- all: Create both the above

##### Output Naming

In 'vars' or 'all' mode, this plugin will create CSS Variables in the following
format:

```css
--icon-{name}-{directory}-{color}: url('{contents}')
```

In 'utils' or 'all' mode, this plugin will create utility classes in the
following format:

```css
.icon-{name}-{directory}-{color} {
  background-image: url('{contents}')
}
```

In each example, the `{directory}` names are only appended if there are more
than one directory in the `dirs` configuration whereas the `{color}` name is
appended only if the `colorize` option is set to true.

##### Purge

Note that utils mode is purged, whereas vars are added to `:root` and are not
purged.

#### Default Options

All keys are optional and will resolve to the contents of
`src/defaultOptions.js` if no user options are chosen. User and Default options
are merged with preference for user options.

```js
module.exports = {
  svgs: {
    colors,
    colorize: false,
    dirs: {
      outline,
      solid,
    },
    mode,
  },
};
```

By default this plugin provides 10 Tailwind
[Heroicons](https://github.com/tailwindlabs/heroicons) to keep the initial size
of the package small and to demonstrate what the plugin can do. However, it's
best to use your own icons for this plugin. Tailwind’s Heroicons are a great
start if you don’t have specific assets generated by design. We do recommend
only including the icons you need as the CSS vars that this plugin uses can’t be
purged.

## Local development

1. Clone the repository:

   ```bash
   git clone https://github.com/jryanconklin/tailwind-svg-import tailwind-svg-import

   cd tailwind-svg-import
   ```

2. Install the dependencies:

   ```bash
   # Using npm
   npm install

   # Using Yarn
   yarn
   ```

3. Add as a plugin to your project.

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