All Projects → TodayTix → Svg Sprite Webpack Plugin

TodayTix / Svg Sprite Webpack Plugin

Licence: mit
Webpack plugin for loading/extracting SVGs into a sprite file

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Svg Sprite Webpack Plugin

Webpack Tools
☕️Just a simple webpack sample project.
Stars: ✭ 106 (+45.21%)
Mutual labels:  webpack-plugin, webpack-loader
React Webpack4 Cook
💯The most powerful webpack4 tutorial in the universe
Stars: ✭ 152 (+108.22%)
Mutual labels:  webpack-plugin, webpack-loader
Webpack Core Usage
webpack2完整系列课程,欢迎阅读。同时欢迎移步我的react全家桶文章全集: https://github.com/liangklfangl/react-article-bucket
Stars: ✭ 94 (+28.77%)
Mutual labels:  webpack-plugin, webpack-loader
Webpack.js.org
Repository for webpack documentation and more!
Stars: ✭ 2,049 (+2706.85%)
Mutual labels:  webpack-plugin, webpack-loader
webpack-demos
webpack小练习
Stars: ✭ 17 (-76.71%)
Mutual labels:  webpack-plugin, webpack-loader
Awesome Cms Core
Awesome CMS Core is an open source CMS built using ASP.Net Core & ReactJS with module seperation concern in mind and provide lastest trend of technology like .Net Core, React, Webpack, SASS, Background Job, Message Queue.
Stars: ✭ 352 (+382.19%)
Mutual labels:  webpack-plugin, webpack-loader
Svg Sprite Loader
Webpack loader for creating SVG sprites.
Stars: ✭ 1,822 (+2395.89%)
Mutual labels:  webpack-plugin, webpack-loader
Workerize Loader
🏗️ Automatically move a module into a Web Worker (Webpack loader)
Stars: ✭ 2,135 (+2824.66%)
Mutual labels:  webpack-plugin, webpack-loader
image-minimizer-webpack-plugin
Webpack loader and plugin to compress images using imagemin
Stars: ✭ 180 (+146.58%)
Mutual labels:  webpack-plugin, webpack-loader
stylos
Webpack plugin to automatically generate and inject CSS utilities to your application
Stars: ✭ 60 (-17.81%)
Mutual labels:  webpack-plugin, webpack-loader
Mpx Webpack Plugin
原生小程序开发定制 webpack 插件套装
Stars: ✭ 34 (-53.42%)
Mutual labels:  webpack-plugin, webpack-loader
H2d2 Shopicons
Essentials E-Commerce icon pack for free.
Stars: ✭ 67 (-8.22%)
Mutual labels:  icons
Phosphor Icons
A flexible icon family for the web
Stars: ✭ 56 (-23.29%)
Mutual labels:  icons
Govicons
🇺🇸 US Government themed icons and CSS toolkit
Stars: ✭ 60 (-17.81%)
Mutual labels:  icons
Iconhandler
Tint you Icons, change the size, apply alpha color and set a position easily. 👓
Stars: ✭ 59 (-19.18%)
Mutual labels:  icons
Vue Builder Webpack Plugin
Webpack plugin to build vue files automatically
Stars: ✭ 70 (-4.11%)
Mutual labels:  webpack-plugin
Xcodeicontagger
Adds version and commit hash as an overlay to your iOS app's icon.
Stars: ✭ 66 (-9.59%)
Mutual labels:  icons
Boxicons
High Quality web friendly icons
Stars: ✭ 1,104 (+1412.33%)
Mutual labels:  icons
Yaru Plus
Yaru++, an elegant and modern third-party icons theme, based on Ubuntu's Yaru
Stars: ✭ 59 (-19.18%)
Mutual labels:  icons
Anicons
Anicons: a new kind of icon fonts with baked-in animation and colors
Stars: ✭ 59 (-19.18%)
Mutual labels:  icons

SVG Sprite Webpack Plugin

NPM Version Build Status Downloads Stats

Description

A webpack plugin/loader to make SVG <use>-based icon systems easy in Webpack. Creates an SVG sprite with <symbol> tags from imported SVG files, and returns a URL to be passed to an SVG <use> tag. Uses kisenka's svg-sprite-loader for internal transformations (from standalone SVG file to <symbol> tag).

Installation

npm install --save-dev svg-sprite-webpack-plugin

Usage

Webpack config

const IconPlugin = require('svg-sprite-webpack-plugin').plugin;

// NOTE:
// Usage with the included webpack-isomorphic-tools parser requires that
// the extracted filename match this format.
const iconPlugin = new IconPlugin('icons-[hash].svg');

// ... inside the configuration object
{
  module: {
    loaders: [
      {
        test: /\.svg$/,
        loader: iconPlugin.extract(),
      }
    ]
  },
  plugins: [
    iconPlugin,
  ],
}

Webpack isomorphic tools

If using webpack-isomorphic-tools, add this to your config:

const iconParser = require('svg-sprite-webpack-plugin').webpackIsomorphicParser;

{
  assets: {
    svg: {
      extension: 'svg',
      parser: iconParser,
    }
  }
}

In code

An example using React 0.14 or later:

import { Component } from 'react';
import myGreatIcon from './my-great-icon.svg';

class SuperGreatIconComponent extends Component {
  render() {
    return (
      <svg><use xlinkHref={myGreatIcon} /></svg>
    );
  }
}

Suggested development mode config

If you're using the webpack-dev-server, it's advised to not use this plugin, and instead go directly to svg-sprite-loader.

const iconTest = /\.svg$/;
if (DEV) {
  config.module.loaders.push({
    test: iconTest,
    loader: 'svg-sprite',
  });
} else {
  config.module.loaders.push({
    test: iconTest,
    loader: iconPlugin.extract(),
  });
}

Usage Caveats

Internet Explorer

Internet Explorer does not support <use> tags with external references. This has been fixed in Microsoft Edge 13, but until Edge's browser share gets to an acceptable level for you, I suggest using jonathantneal's excellent SVG4Everybody library.

CDNs

<use> tags do not allow cross-origin requests, and from what I could tell, aren't likely to start supporting them any time soon. Because of this, instead of using the output.publicPath webpack config, this library is currently expecting that the generated icons svg will be accessible inside the /static directory on the same domain as the website using the imported icons.

Development

This was originally developed to be used in-house, so I expect there are a number of usecases that are not being adequately covered. Issues and PRs are welcome!

Install dependencies:

npm install --global yarn
yarn install

Make sure any code passes tests and the linter before submitting a PR!

yarn test
yarn run lint

Meta

Distributed under the MIT License. See LICENSE for more information.

Developers:

Jeremy Tice @jetpacmonkey

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