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

export-svg-loader

v0.1.0

Published

A webpack loader which exports SVG files to image files.

Downloads

5

Readme

export-svg-loader

A webpack loader to convert SVGs to images built with svg-to-img.

Getting Started

Installation

To use export-svg-loader in your project, run:

npm install export-svg-loader -D

Note This project uses await/async then node v7.6.0 or greater it's required to work.

Usage

The loader may be configured to export a single or multiple extensions with varying dimensions.

  • type - (Optional). Extension that svg file is going to be exported. Default to png.
  • fileName - (Optional). A template string for the output file name. Defaults to [svg-file-name].[extension]. Also you can send as array to export multiple images.
  • sizes - (Optional). Used to export multiple images for a single input SVG. Holds an array of sizes. Size entries may be formatted like [height]x[width] (e.g. 57x32). Also can send as string for one unique export or just [number] (e.g. 57) for square dimensions.
  • publicPath: (Optional). Places where the image is going to be exported. It's necessary to set as relative path to output.

Example - converting a svg to png:

module.exports = {
  //...
  module: {
    rules: [
      { test: /\.svg$/, use: ['export-svg-loader'] }
    ];
  }
}

Example - converting a svg to ico and saving the image as example.jpeg:

module.exports = {
  //...
  module: {
    rules: [
      {
        test: /\.svg$/,
        use: {
          loader: 'export-svg-loader',
          options: {
            type: 'ico'
          }
        }
      }
    ];
  }
}

Example - converting a svg to jpeg and saving the image as example.jpeg:

module.exports = {
  //...
  module: {
    rules: [
      {
        test: /\.svg$/,
        use: {
          loader: 'export-svg-loader',
          options: {
            type: 'jpeg',
            fileName: 'example'
          }
        }
      }
    ];
  }
}

Example - resizing a svg proportionally and converting it to webp in dist/images folder :

module.exports = {
  //...
  module: {
    rules: [
      {
        test: /\.svg$/,
        use: {
          loader: 'export-svg-loader',
          options: {
            type: 'webp',
            publicPath: 'dist/images'
          }
        }
      }
    ];
  }
}

Example - converting a svg to png with width 40 and height 30:

module.exports = {
  //...
  module: {
    rules: [
      {
        test: /\.svg$/,
        use: {
          loader: 'export-svg-loader',
          options: {
            sizes: ['40x30']
          }
        }
      }
    ];
  }
}

Example - converting a svg to png with width 40 and height 40 as number:

module.exports = {
  //...
  module: {
    rules: [
      {
        test: /\.svg$/,
        use: {
          loader: 'export-svg-loader',
          options: {
            sizes: 40
          }
        }
      }
    ];
  }
}

Example - converting a svg to png with the follow sizes: 30x30, 40x40, 70x90:

module.exports = {
  //...
  module: {
    rules: [
      {
        test: /\.svg$/,
        use: {
          loader: 'export-svg-loader',
          options: {
            sizes: ['30x30', '40x40', '70x90']
          }
        }
      }
    ];
  }
}

Note - If we don't specify an array of custom name it will generate images with the width dimension. Example: icon30.png, icon40.png and icon70.png

Example - converting a svg to png with the follow sizes: 30x30, 40x40, 70x90 and an array of custom names:

module.exports = {
  //...
  module: {
    rules: [
      {
        test: /\.svg$/,
        use: {
          loader: 'export-svg-loader',
          options: {
            sizes: ['30x30', '40x40', '70x90'],
            fileName: ['image30x30', 'image40x40', 'image70x90']
          }
        }
      }
    ];
  }
}

Built with

  • node.js - Cross-platform JavaScript run-time environment for executing JavaScript code server-side.
  • Jest - Delightful JavaScript Testing.

Contributing

When contributing to this project, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

Update the README.md with details of changes to the library.

Execute npm run test and update the tests if needed.

License

This project is licensed under the MIT License - see the LICENSE file for details.