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

svg-sprite-vue-generator

v1.0.6

Published

Vue component runtime generator for svg-sprite-loader.

Downloads

10

Readme

svg-sprite-vue-generator

Vue component runtime generator for svg-sprite-loader.

Install

npm install svg-sprite-vue-generator -D

Usage

Inline mode

All svg icon will be inline to part of the component.

Inline mode is default mode from svg-sprite-loader. It called spriteModule.

  • https://github.com/JetBrains/svg-sprite-loader#spritemodule-autoconfigured
import FacebookSprite from './assets/facebook.sprite.svg'
import TwitterSprite from './assets/twitter.sprite.svg'
import wikipedia from './assets/wikipedia.svg'

// FacebookSprite will be a valid vue component, use it as an vue component

console.log(FacebookSprite)
// render as: <svg><use xlink:href="#facebook.sprite"></use></svg>

console.log(TwitterSprite)
// render as: <svg><use xlink:href="#twitter.sprite"></use></svg>

// wikipedia still be an normal asset url, use it as normal image asset url in html img tag or css background-image

console.log(wikipedia)
// log as: /static/img/wikipedia.77b80eb8.svg

Config

May be need to install related loaders, such as:

  • babel-loader
  • svgo-loader
// vue.config.js
module.exports = {
  chainWebpack: config => {
    // default file-loader
    config.module.rule('svg')
      .exclude.add(/\.sprite\.(svg)(\?.*)?$/).end()

    // add svg-sprite-loader
    config.module.rule('svg-sprite')
      .test(/\.sprite\.(svg)(\?.*)?$/)
      .use('babel-loader').loader('babel-loader').end()
      .use('svg-sprite-loader').loader('svg-sprite-loader').tap(() => {
        return {
          runtimeGenerator: require.resolve('svg-sprite-vue-generator'),
        }
      }).end()
      .use('svgo-loader').loader('svgo-loader')
  }
}

Extract mode

All svg file will be group to an independent svg file.

  • https://github.com/JetBrains/svg-sprite-loader#extract-default-false-autoconfigured
import FacebookSprite from './assets/facebook.sprite.svg'
import TwitterSprite from './assets/twitter.sprite.svg'
import TwitterSpriteURL from './assets/twitter.sprite.svg?URL'
import wikipedia from './assets/wikipedia.svg'

// FacebookSprite will be a valid vue component, use it as an vue component
// It will be render as an normal img or svg tag with src to an an independent svg file(include all svg sprite)

console.log(FacebookSprite)
// render as: <svg><use xlink:href="/static/sprite.svg#facebook.sprite-usage"></use></svg>
// render as img: <img src="/static/sprite.svg#twitter.sprite--url-usage">

console.log(TwitterSprite)
// render as: <svg><use xlink:href="/static/sprite.svg#twitter.sprite-usage"></use></svg>

// TwitterSpriteURL will be an normal url, use it as normal image asset in html img tag or css background-image
console.log(TwitterSpriteURL)
// log as: /static/sprite.svg#twitter.sprite--url-usage

// wikipedia still be an normal asset, use it as normal image asset in html img tag or css background-image

console.log(wikipedia)
// log as: /static/img/wikipedia.77b80eb8.svg

Config

May be need to install related loaders, such as:

  • svgo-loader
// vue.config.js
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin')

module.exports = {
  assetsDir: 'static',
  configureWebpack: {
    plugins: [
      // NOTE: for extract mode, un support https://github.com/JetBrains/svg-sprite-loader#plain-sprite
      new SpriteLoaderPlugin()
    ]
  },
  chainWebpack: config => {
    // default file-loader
    config.module.rule('svg')
      .exclude.add(/\.sprite\.(svg)(\?.*)?$/).end()

    // add svg-sprite-loader
    config.module.rule('svg-sprite')
      .test(/\.sprite\.(svg)(\?.*)?$/)
      .use('svg-sprite-loader').loader('svg-sprite-loader').tap(() => {
        return {
          runtimeGenerator: require.resolve('svg-sprite-vue-generator'),
          runtimeOptions: {
            // default render svg tag, set it true to render img tag
            extractCompTagImg: false,
          },
          extract: true,
          publicPath: '/static/'
        }
      }).end()
      .use('svgo-loader').loader('svgo-loader')
  }
}

TypeScript

add module declare for typescript.

declare module "*.sprite.svg" {
  import Vue, { VueConstructor } from 'vue'
  const content: VueConstructor<Vue>
  export default content
}

Runtime Options

Use runtime options to config more

{
  // default render svg tag, set it true to render img tag in extract mode
  extractCompTagImg: false,
  // bind any attributes, default is empty
  attrs: {},
  // set loading class, default is 'svg-sprite-loading'
  loadingClass: '',
  // set any class string, default is ''
  otherClass: '',
}

Note

  • Can not use inline and extract mode together
  • May be you can use just extract mode for all svg file

Demo

npm run demo:serve