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

ym-svg-sprite

v1.3.0

Published

<a href="https://www.npmjs.com/package/ym-svg-sprite"> <img src="https://img.shields.io/npm/v/ym-svg-sprite.svg" alt="NPM"> </a> <a href="https://github.com/sishenhei7/ym-svg-sprite/blob/master/LICENSE"> <img src="https://img.shields.io/github/license

Downloads

18

Readme

ym-svg-sprite

ym-svg-sprite is used to build svg sprite in vue

How

This plugin uses 'file-loader' to load normal svg files, and uses 'svg-sprite-loader' to build svg sprite.

Also, it uses 'svgo' and 'svgo-loader' to compress svg sprite.(It deletes the titles and annotations in svg)

Getting Started

install

To begin with, just install ym-svg-sprite:

npm i ym-svg-sprite -s

vue.config.js

Then add these settings to your vue.config.js file(if it does not exist, create one):

const path = require("path");

module.exports = {
  chainWebpack: config => {
    const resolve = dir => path.join(__dirname, dir);
    const svgRule = config.module.rule('svg');
    svgRule.uses.clear();

    svgRule
      .test(/\.(svg)(\?.*)?$/)
      .oneOf('name')
        .include
          .add(resolve('src/assets/sprite.svg'))
          .end()
        .use('file-loader')
          .loader('file-loader')
          .options({
            name: 'img/[name].[hash:8].[ext]'
          })
          .end()
        .end()
      .oneOf('normal')
        .exclude
          .add(resolve('src/assets/sprite'))
          .end()
        .use('file-loader')
          .loader('file-loader')
          .options({
            name: 'img/[name].[hash:8].[ext]'
          })
          .end()
        .end()
      .oneOf('sprite')
        .include
          .add(resolve('src/assets/sprite'))
          .end()
        .use('svg-sprite-loader')
          .loader('svg-sprite-loader')
          .options({
            symbolId: 'sprite-[name]'
          })
          .end()
        .use('svgo-loader')
          .loader('svgo-loader')
          .options({
            plugins: [
              {removeTitle: true},
              {convertColors: {shorthex: false}},
              {convertPathData: false}
            ]
          });
  },
};

tips

All your svg files (to be built into svg sprite) should be placed under src/assets/sprite folder.

main.js

Finally, import ym-svg-sprite in your main.js:

import SvgSprite from 'ym-svg-sprite';

Vue.use(SvgSprite);
const requireAll = requireContext => requireContext.keys().map(requireContext);
const req = require.context('./assets/sprite', false, /\.svg$/);
requireAll(req);

tips

You can modify src/assets/sprite in both vue.config.js and main.js to change the default sprite folder.

examples

You can use YmSvg as a vue component anywhere like this:

<ym-svg svgName="haha" className="app-svg"/>

tips

svgName is required, it is the name of your svg file.

ToDo

  • [x] implement svgo plugin.
  • [ ] change it to vue-cli3 plugin.