All Projects → crystal-ball → svg-symbol-sprite-loader

crystal-ball / svg-symbol-sprite-loader

Licence: ISC license
Loader and plugin for generating an SVG symbol sprite

Programming Languages

javascript
184084 projects - #8 most used programming language
Dockerfile
14818 projects
HTML
75241 projects

Projects that are alternatives of or similar to svg-symbol-sprite-loader

Vue Svg Inline Loader
Webpack loader used for inline replacement of SVG images with actual content of SVG files in Vue projects.
Stars: ✭ 105 (+600%)
Mutual labels:  sprites, loader
jquery-svg-convert
Convert .svg images to code on the fly with jQuery
Stars: ✭ 30 (+100%)
Mutual labels:  svg-icons
elm-feather
Feather icons for elm
Stars: ✭ 73 (+386.67%)
Mutual labels:  svg-icons
crypto-icons
Cryptocurrency icons by Guarda
Stars: ✭ 54 (+260%)
Mutual labels:  svg-icons
django-manifest-loader
Simplifies webpack configuration with Django
Stars: ✭ 105 (+600%)
Mutual labels:  loader
svg-gobbler
Open source browser extension that makes designing and developing easier by finding, processing, exporting, optimizing, and managing SVG content.
Stars: ✭ 272 (+1713.33%)
Mutual labels:  svg-icons
font-gis
Icon font and SVG for use with GIS and spatial analysis tools
Stars: ✭ 121 (+706.67%)
Mutual labels:  svg-icons
gba-sprite-engine
An object-oriented Game Boy Advance sprite engine concept
Stars: ✭ 68 (+353.33%)
Mutual labels:  sprites
Thomas-George-T
Readme for Github Profile. Don't just fork it, Star it too ⭐!
Stars: ✭ 31 (+106.67%)
Mutual labels:  svg-icons
rails-heroicon
Ruby on Rails views helpers for the awesome heroicons by Steve Schoger.
Stars: ✭ 23 (+53.33%)
Mutual labels:  svg-icons
ember-content-loader
Easy, customizable content placeholders / skeletons screens
Stars: ✭ 41 (+173.33%)
Mutual labels:  loader
Solaris
A local LKM rootkit loader/dropper that lists available security mechanisms
Stars: ✭ 47 (+213.33%)
Mutual labels:  loader
SVGLoadersPack-Android
Android SVGLoadersPack - SVG animations and Loaders in Android
Stars: ✭ 27 (+80%)
Mutual labels:  loader
composer-file-loader
Tool to load namespaces and classes from composer.json file without composer
Stars: ✭ 64 (+326.67%)
Mutual labels:  loader
angular-translate-loader
"angular-translate" loader for webpack
Stars: ✭ 15 (+0%)
Mutual labels:  loader
Centrifuge
Cross-platform runtime mod loader and API for any Unity-based game. Supports Unity 5 and up!
Stars: ✭ 27 (+80%)
Mutual labels:  loader
react-data-loader
Dead simple data loader helper for React
Stars: ✭ 22 (+46.67%)
Mutual labels:  loader
react-crud-icons
57 SVG icons for CRUD applications, packaged as a React component with light & dark themes and tooltip.
Stars: ✭ 19 (+26.67%)
Mutual labels:  svg-icons
vue-loading
Loading bar for Vue.js apps using axios
Stars: ✭ 19 (+26.67%)
Mutual labels:  loader
unity-surfaceshader-flipbook
Surface shaders with flipbook / spritesheet animation functionality
Stars: ✭ 43 (+186.67%)
Mutual labels:  sprites

Crystal Ball Projects documentation

Package version NPM downloads Build status Known vulnerabilities Test coverage Maintainability :status      
Renovate Commitizen friendly ZenHub Semantic Release Contributor Covenant :integrations
Contains magic Full of love :flair       


webpack loader and plugin for creating SVG sprites



Install

npm install svg-symbol-sprite-loader

Configuration guide

The ultimate SVG icon system follows this workflow:

  1. SVGs are imported into your application using the webpack loader, they can be referenced by their ID.
  2. The imported SVGs are deduped, sorted, hashed and extracted by the webpack plugin.
  3. The package exports a localStorage cache loader for browser bundles that will import the emitted sprite. If the sprite contents change, the filename hash will change and the sprite loader will fetch the latest sprite.

ℹ️ See the test application for a complete application example

1. Configure - webpack.config.js

const SVGSymbolSprite = require('svg-symbol-sprite-loader')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {

  // ...

  module: {
    rules: [
      {
        // The loader transforms imported SVGs in JS objects of SVG data that
        // can be used with any icon component
        test: /\.svg$/,
        use: [
          {
            loader: 'svg-symbol-sprite-loader',

            // optional: Provide a function which returns a customized symbol ID.
            // It receives the full file path as an argument
            options: {
              symbolId: filePath => `icon-${path.basename(filePath, '.svg')}`,
            },
          },
        ],
      },
      // ...
    ],
  },
    plugins: [
      // The plugin will append a script with the sprite hash to head
      // ⚠️ Order matters, the HTML plugin must be included before the SVG sprite
      // plugin so that the HTML plugin hooks are registered!
      new HtmlWebpackPlugin(),

      // The plugin extracts the imported SVGs into a separate sprite file,
      new new SVGSymbolSprite.Plugin({
        filename: `icon-sprite${process.env.NODE_ENV === 'production' ? '.[chunkhash]' : ''}.svg`
      }),
    ],
  }
}

2. Fetch - application source

import svgSymbolSpriteLoader from 'svg-symbol-sprite-loader'

// Call the sprite loader to fetch and cache the latest SVG sprite.
svgSymbolSpriteLoader({ useCache: process.env.NODE_ENV === 'production' })

3. Import - application source

import iconOne from './media/icon-one.svg'

  // ...
export default () => (
  <svg>
    <use href={`#${iconOne.id}`}>
  </svg>
)

SVG icon system motivation

  • Sprite only the SVG icons imported into your application.
  • Use local storage to cache sprites by content hash and only fetch a sprite when its content has changed.
  • Load sprites from CDN locations without the CORS issues of relative SVG imports.
  • Symbol sprites are very effective for creating an icon system. They allows svgs to be referenced by id, and don't require including viewbox attributes.

Contributing 😃

All contributions are greatly appreciated 👍🎉. To contribute please:

Thank You 🙏

Repo icon made by Smartline from www.flaticon.com is licensed by CC 3.0 BY
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].