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

neumedia-svg-icon

v1.0.5

Published

使用`svg-sprite-loader`替换默认的`file-loader`加载svg图形:

Downloads

2

Readme

优雅的引入SVG图形

使用svg-sprite-loader替换默认的file-loader加载svg图形:

安装插件

安装svg-sprite-loader

yarn add svg-sprite-loader

注册组件

将组件文件置于src/components/目录下;

src/assets/目录下建立icons/svg目录;

配置webpack,打开vue.config.js,并增加下面内容:

// 重新定义 svg loader,使用 svg-sprite-loader 作为默认 svg 加载器使用
const svgRule = config.module.rule('svg');
svgRule.uses.clear();
svgRule.exclude.add(/node_modules/); // 正则匹配排除node_modules目录
svgRule // 添加svg新的loader处理
  .test(/\.svg$/)
  .use('svg-sprite-loader')
  .loader('svg-sprite-loader')
  .options({
  	symbolId: 'icon-[name]'
  });
  
// 重新定义 images loader
const imagesRule = config.module.rule('images');
imagesRule.exclude.add(resolve('src/assets/icons'));
config.module.rule('images').test(/\.(png|jpe?g|gif|svg)(\?.*)?$/);

全局注册svg-icon组件,打开并修改main.js文件:

import SvgIcon from '@/components/SvgIcon';
Vue.component('svg-icon', SvgIcon);
const requireAll = requireContext => requireContext.keys().map(requireContext);
const req = require.context('./assets/icons/svg', false, /\.svg$/);
requireAll(req);

组件使用

将svg图片置于src/assets/icons/svg目录下,如src/assets/icons/svg/demo.svg

设置svg图片中的fill属性:

fill="currentColor"
// 或
fill=""
// 或直接删除fill属性

在组件中使用标签svg-icon对组件进行引用:

<svg-icon iconClass="demo" className="class-name"></svg-icon>