npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tailwind-svg-import

v0.4.0

Published

Import your file system svgs to Tailwind.

Downloads

1,644

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:
# Using npm
npm install tailwind-svg-import --save-dev

# Using Yarn
yarn add tailwind-svg-import -D
  1. Add it to your tailwind.config.js file:
// 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 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:

'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:

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

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

.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.

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

By default this plugin provides 10 Tailwind 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:

    git clone https://github.com/jryanconklin/tailwind-svg-import tailwind-svg-import
    
    cd tailwind-svg-import
  2. Install the dependencies:

    # Using npm
    npm install
    
    # Using Yarn
    yarn
  3. Add as a plugin to your project.