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

snowpack-svgr-plugin

v1.0.3

Published

A simple snowpack plugin to transform SVG files to HTML SVG using react

Downloads

56

Readme

snowpack-svgr-plugin

this plugin will let you import SVG files and use them as a react component and transform them to browser as normal SVG

This plugin use svgr to transform/convert SVG Files into ready to use React components, then use @babel/preset-react to transform it to browser code

Installing

$ npm i -D snowpack-svgr-plugin

Getting start

Add the plugin to snowpack.config.js

  plugins: [
   ...
      'snowpack-svgr-plugin',
  ]

Supported files

We use an odd technique to prevent transforming all SVG files

only files that endsup with *.svgr.svg will be transformed

this was the quicker solution that come to my mind to overpass the lake of filtering option in the snowpack API

the reason of filtering is because this plugin will replace the targeted files with the generated code so you will not be able to use these JS files as normal SVG like inside HTML <img> tag or whatever,but with filtering you can control this habbet.

example

home.svg->not transformed

messages.svgr.svg->transformed

Using with ReactJS

Import your SVG files as you normally do

import mySvg from '../mySvg.svgr.svg';

then use it as a normal react component

 const App=() {
  return (
    <div className="app">
   <mySvg/>
      </div>)

Using with ReactTs

using TypeScript you just need to add the type definition to *.svgr.svg file add those Line to your d.ts file:

declare module '*.svgr.svg' {
  const ref: React.ForwardRefRenderFunction<
    SVGSVGElement,
    React.SVGAttributes<SVGSVGElement>
  >;
  export default ref;
}

now you will be able to import your svgr.svg files without type problems and use them the same as normal JS with some types spices.

What's next

hopfully its will be a better solution for filtering like to be able to include/exclude folders. Im not planing on investigate more in the Snowpack API But I will accept the Good Solutions and ideas via PR so if someone want to help or fork i will appreciate it.

  • Also if you have any problems or issues using this plugin please make sure to Create a Issue