svg-sprite-loader vs svg-sprite vs gulp-svgmin vs gulp-svgstore vs gulp-svg-sprite vs gulp-iconfont
SVG Processing and Icon Management in Web Development Comparison
1 Year
svg-sprite-loadersvg-spritegulp-svgmingulp-svgstoregulp-svg-spritegulp-iconfontSimilar Packages:
What's SVG Processing and Icon Management in Web Development?

These npm packages are designed to streamline the process of handling SVG graphics and icons in web development. They provide various functionalities such as creating icon fonts from SVG files, generating SVG sprites for optimized loading, minimizing SVG files for better performance, and managing SVG assets efficiently. By using these tools, developers can enhance their workflow, reduce load times, and ensure that their applications are visually appealing and performant.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
svg-sprite-loader196,3012,027-1483 years agoMIT
svg-sprite146,5701,953213 kB54a year agoMIT
gulp-svgmin55,252340-74 years agoMIT
gulp-svgstore35,32564417 kB13 years agoMIT
gulp-svg-sprite33,77865013.4 kB12 years agoMIT
gulp-iconfont21,70385342.6 kB148 months agoMIT
Feature Comparison: svg-sprite-loader vs svg-sprite vs gulp-svgmin vs gulp-svgstore vs gulp-svg-sprite vs gulp-iconfont

Icon Font Generation

  • svg-sprite-loader:

    svg-sprite-loader integrates SVG sprites into modern JavaScript frameworks, allowing SVG files to be imported as components, but does not handle icon font generation.

  • svg-sprite:

    svg-sprite focuses on generating SVG sprites with advanced features, allowing for customization and optimization of the output, but does not create icon fonts.

  • gulp-svgmin:

    gulp-svgmin does not generate icon fonts or sprites but optimizes SVG files by minimizing their size, which can indirectly benefit icon font generation by reducing the size of the original SVG files.

  • gulp-svgstore:

    gulp-svgstore allows developers to create a single SVG sprite from multiple SVG files, which can be referenced in the HTML. This package is useful for managing SVG assets without generating a font.

  • gulp-svg-sprite:

    gulp-svg-sprite does not focus on icon font generation but rather on creating SVG sprite sheets. It combines multiple SVG files into a single sprite, which can be referenced in the HTML, reducing the number of HTTP requests.

  • gulp-iconfont:

    gulp-iconfont enables the conversion of SVG files into icon fonts, allowing developers to use scalable vector icons in their projects. This package supports various font formats and provides options for customizing the output, such as font naming and styles.

Performance Optimization

  • svg-sprite-loader:

    svg-sprite-loader improves performance by allowing SVG sprites to be used as components, which can be optimized and lazy-loaded in modern applications.

  • svg-sprite:

    svg-sprite provides performance benefits through sprite generation and optimization features, ensuring that the final output is efficient and lightweight for web use.

  • gulp-svgmin:

    gulp-svgmin is specifically designed for performance optimization, minimizing SVG files to reduce their size and improve loading speed, making it essential for performance-focused projects.

  • gulp-svgstore:

    gulp-svgstore enhances performance by consolidating SVG assets into a single file, which can be loaded once and reused throughout the application, reducing load times.

  • gulp-svg-sprite:

    gulp-svg-sprite optimizes performance by reducing the number of HTTP requests through sprite generation, which can significantly enhance load times for web applications.

  • gulp-iconfont:

    gulp-iconfont does not directly optimize performance but provides a scalable solution for using icons, which can improve rendering times when using font files instead of multiple image files.

Ease of Use

  • svg-sprite-loader:

    svg-sprite-loader is designed for use with Webpack, making it easy to integrate SVG sprites into modern applications, but may require familiarity with Webpack configuration.

  • svg-sprite:

    svg-sprite offers a range of features but may have a steeper learning curve due to its advanced customization options, making it better suited for experienced developers.

  • gulp-svgmin:

    gulp-svgmin is easy to integrate into existing Gulp workflows, allowing for quick optimization of SVG files with minimal configuration required.

  • gulp-svgstore:

    gulp-svgstore is relatively easy to use, providing a simple way to manage SVG assets and create a single sprite file, but may require some understanding of Gulp tasks.

  • gulp-svg-sprite:

    gulp-svg-sprite is user-friendly for creating SVG sprites, with clear documentation and examples, making it accessible for developers of all skill levels.

  • gulp-iconfont:

    gulp-iconfont is straightforward to use for developers familiar with Gulp, providing a simple API for creating icon fonts from SVG files, but may require additional setup for font management.

Integration with Build Tools

  • svg-sprite-loader:

    svg-sprite-loader is specifically designed for Webpack, allowing for easy integration into modern JavaScript applications, but is not compatible with Gulp.

  • svg-sprite:

    svg-sprite can be used independently of Gulp, but it may require additional setup for integration with build tools, making it less straightforward for Gulp users.

  • gulp-svgmin:

    gulp-svgmin integrates smoothly with Gulp, enabling developers to include SVG optimization in their build processes without much hassle.

  • gulp-svgstore:

    gulp-svgstore is tailored for Gulp, making it easy to incorporate into existing Gulp tasks for managing SVG assets efficiently.

  • gulp-svg-sprite:

    gulp-svg-sprite is also designed for Gulp, allowing for easy integration into Gulp workflows, which is beneficial for developers already using Gulp for task automation.

  • gulp-iconfont:

    gulp-iconfont is built specifically for Gulp, making it a natural choice for projects that already use Gulp as their build tool, ensuring seamless integration.

Customization Options

  • svg-sprite-loader:

    svg-sprite-loader allows for customization in how SVGs are imported and used as components, providing flexibility for developers working with modern frameworks.

  • svg-sprite:

    svg-sprite provides extensive customization options for sprite generation, allowing developers to fine-tune the output to meet specific project needs, making it suitable for complex applications.

  • gulp-svgmin:

    gulp-svgmin focuses on optimization rather than customization, providing limited options for altering SVG files beyond minimizing their size.

  • gulp-svgstore:

    gulp-svgstore allows for some customization in how SVGs are stored and referenced, but is primarily focused on asset management rather than extensive customization.

  • gulp-svg-sprite:

    gulp-svg-sprite offers some customization options for sprite generation, such as output format and naming conventions, but may not be as flexible as other packages for complex requirements.

  • gulp-iconfont:

    gulp-iconfont provides various customization options for font generation, including the ability to specify font names, styles, and formats, allowing for tailored icon font solutions.

How to Choose: svg-sprite-loader vs svg-sprite vs gulp-svgmin vs gulp-svgstore vs gulp-svg-sprite vs gulp-iconfont
  • svg-sprite-loader:

    Select svg-sprite-loader if you are using Webpack and need to import SVG files as React components or Vue components. This loader allows you to easily integrate SVG sprites into your components, providing a seamless development experience with modern frameworks.

  • svg-sprite:

    Choose svg-sprite when you require a more comprehensive solution for generating and managing SVG sprites. It provides advanced features for creating sprites, including the ability to customize the output format and optimize the SVGs, making it suitable for complex projects.

  • gulp-svgmin:

    Opt for gulp-svgmin when your focus is on optimizing SVG files for performance. This package minimizes SVG files by removing unnecessary metadata, comments, and whitespace, resulting in smaller file sizes without sacrificing quality, which is crucial for faster loading times.

  • gulp-svgstore:

    Use gulp-svgstore if you want to create an SVG sprite that can be referenced in your HTML. This package allows you to store SVGs in a single file and reference them using <use> tags, which is beneficial for maintaining clean HTML and efficient SVG management.

  • gulp-svg-sprite:

    Select gulp-svg-sprite if you need to combine multiple SVG files into a single sprite sheet. This package is ideal for reducing HTTP requests and improving load times by consolidating your SVG assets into one file, making it easier to manage and use in your application.

  • gulp-iconfont:

    Choose gulp-iconfont if your primary goal is to create icon fonts from SVG files. It allows you to convert multiple SVG icons into a single font file, which can be easily included in your web projects for scalable and customizable icons.

README for svg-sprite-loader

SVG sprite loader

NPM version Build status Documentation score Dependencies status Dev dependencies status NPM downloads

Webpack loader for creating SVG sprites.

:tada: 2.0 is out, please read the migration guide & overview.

:warning: For old v0.x versions see the README in the v0 branch.

Table of contents

Why it's cool

  • Minimum initial configuration. Most of the options are configured automatically.
  • Runtime for browser. Sprites are rendered and injected in pages automatically, you just refer to images via <svg><use xlink:href="#id"></use></svg>.
  • Isomorphic runtime for node/browser. Can render sprites on server or in browser manually.
  • Customizable. Write/extend runtime module to implement custom sprite behaviour. Write/extend runtime generator to produce your own runtime, e.g. React component configured with imported symbol.
  • External sprite file is generated for images imported from css/scss/sass/less/styl/html (SVG stacking technique).

Installation

npm install svg-sprite-loader -D
# via yarn
yarn add svg-sprite-loader -D

Configuration

// webpack 1
{
  test: /\.svg$/,
  loader: 'svg-sprite-loader',
  query: { ... }
}

// webpack 1 multiple loaders
{
  test: /\.svg$/,
  loaders: [
    `svg-sprite-loader?${JSON.stringify({ ... })}`,
    'svg-transform-loader',
    'svgo-loader'
  ]
}

// webpack >= 2
{
  test: /\.svg$/,
  loader: 'svg-sprite-loader',
  options: { ... }
}

// webpack >= 2 multiple loaders
{
  test: /\.svg$/,
  use: [
    { loader: 'svg-sprite-loader', options: { ... } },
    'svg-transform-loader',
    'svgo-loader'
  ]
}

symbolId (string | function(path, query), default [name])

How <symbol> id attribute should be named. All patterns from loader-utils#interpolateName are supported. Also can be a function which accepts 2 args - file path and query string and return symbol id:

{
  symbolId: filePath => path.basename(filePath)
}

symbolRegExp (default '')

Passed to the symbolId interpolator to support the [N] pattern in the loader-utils name interpolator

esModule (default true, autoconfigured)

Generated export format:

  • when true loader will produce export default ....
  • when false the result is module.exports = ....

By default depends on used webpack version: true for webpack >= 2, false otherwise.

Runtime configuration

When you require an image, loader transforms it to SVG <symbol>, adds it to the special sprite storage and returns class instance that represents symbol. It contains id, viewBox and content (id, viewBox and url in extract mode) fields and can later be used for referencing the sprite image, e.g:

import twitterLogo from './logos/twitter.svg';
// twitterLogo === SpriteSymbol<id: string, viewBox: string, content: string>
// Extract mode: SpriteSymbol<id: string, viewBox: string, url: string, toString: Function>

const rendered = `
<svg viewBox="${twitterLogo.viewBox}">
  <use xlink:href="#${twitterLogo.id}" />
</svg>`;

When browser event DOMContentLoaded is fired, sprite will be automatically rendered and injected in the document.body. If custom behaviour is needed (e.g. a different mounting target) default sprite module could be overridden via spriteModule option. Check example below.

spriteModule (autoconfigured)

Path to sprite module that will be compiled and executed at runtime. By default it depends on target webpack config option:

  • svg-sprite-loader/runtime/browser-sprite.build for 'web' target.
  • svg-sprite-loader/runtime/sprite.build for other targets.

If you need custom behavior, use this option to specify a path of your sprite implementation module. Path will be resolved relative to the current webpack build folder, e.g. utils/sprite.js placed in current project dir should be written as ./utils/sprite.

Example of sprite with custom mounting target (copypasted from browser-sprite):

import BrowserSprite from 'svg-baker-runtime/src/browser-sprite';
import domready from 'domready';

const sprite = new BrowserSprite();
domready(() => sprite.mount('#my-custom-mounting-target'));

export default sprite; // don't forget to export!

It's highly recommended to extend default sprite classes:

symbolModule (autoconfigured)

Same as spriteModule, but for sprite symbol. By default also depends on target webpack config option:

  • svg-baker-runtime/browser-symbol for 'web' target.
  • svg-baker-runtime/symbol for other targets.

runtimeGenerator (default generator)

Path to node.js script that generates client runtime. Use this option if you need to produce your own runtime, e.g. React component configured with imported symbol. Example.

runtimeCompat (default false, deprecated)

Should runtime be compatible with earlier v0.x loader versions. This option will be removed in the next major version release.

runtimeOptions

Arbitrary data passed to runtime generator. Reserved for future use when other runtime generators will be created.

Extract configuration

In the extract mode loader should be configured with plugin, otherwise an error is thrown. Example:

// webpack.config.js
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');

...

{
  plugins: [
    new SpriteLoaderPlugin()
  ]
}

extract (default false, autoconfigured)

Switches loader to the extract mode. Enabled automatically for images imported from css/scss/sass/less/styl/html files.

spriteFilename (type string|Function<string>,default sprite.svg)

Filename of extracted sprite. Multiple sprites can be generated by specifying different loader rules restricted with include option or by providing custom function which recieves SVG file absolute path, e.g.:

{
  test: /\.svg$/,
  loader: 'svg-sprite-loader',
  options: {
    extract: true,
    spriteFilename: svgPath => `sprite${svgPath.substr(-4)}`
  }
}

[hash] in sprite filename will be replaced by it's content hash. It is also possible to generate sprite for each chunk by using [chunkname] pattern in spriteFilename option. This is experimental feature, use it with caution!

publicPath (type: string, default: __webpack_public_path__)

Custom public path for sprite file.

{
  test: /\.svg$/,
  loader: 'svg-sprite-loader',
  options: {
    extract: true,
    publicPath: '/'
  }
}

outputPath (type: string, default: null`)

Custom output path for sprite file. By default it will use publicPath. This param is useful if you want to store sprite is a directory with a custom http access.

{
  test: /\.svg$/,
  loader: 'svg-sprite-loader',
  options: {
    extract: true,
    outputPath: 'custom-dir/sprites/'
    publicPath: 'sprites/'
  }
}

Plain sprite

You can render plain sprite in extract mode without styles and usages. Pass plainSprite: true option to plugin constructor:

{
  plugins: [
    new SpriteLoaderPlugin({ plainSprite: true })
  ]
}

Sprite attributes

Sprite <svg> tag attributes can be specified via spriteAttrs plugin option:

{
  plugins: [
    new SpriteLoaderPlugin({
      plainSprite: true,
      spriteAttrs: {
        id: 'my-custom-sprite-id'
      }
    })
  ]
}

Examples

See examples folder.

Contributing guidelines

See CONTRIBUTING.md.

License

See LICENSE

Credits

Huge thanks for all this people.