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-to-react-webpack-loader

v0.1.2

Published

A [webpack](https://webpack.js.org/) loader that allows you to import .svg files into a [React](https://reactjs.org/) app and have them inlined without incurring an additional HTTP request.

Downloads

4

Readme

svg-to-react-webpack-loader

A webpack loader that allows you to import .svg files into a React app and have them inlined without incurring an additional HTTP request.

Also allows you to add props onto the <svg> element at run-time, and a <title> and <desc> for accessibility.

Unmaintained

Use @svgr/webpack, add these rules to your webpack.config.js:

const webpackConfig = {
    module: {
        rules: [
            ...
            {
                type: 'asset',
                resourceQuery: /\burl\b/,  // *.svg?url
                parser: {
                    dataUrlCondition: {
                        maxSize: 200,
                    }
                }
            },
            {
                test: /\.svg$/i,
                issuer: /\.tsx$/,
                loader: '@svgr/webpack',
                options: {
                    titleProp: true,
                }
            },
            ...

And add a file to your project, types/svgr.d.ts:

declare module '*.svg' {
    const component: React.FC<React.SVGProps<SVGSVGElement> & {title?: string}>;
    export default component;
}

Compilation

Input

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512">
    <path d="M285.476 272.971L91.132 467.314c-9.373 9.373-24.569 9.373-33.941 0l-22.667-22.667c-9.357-9.357-9.375-24.522-.04-33.901L188.505 256 34.484 101.255c-9.335-9.379-9.317-24.544.04-33.901l22.667-22.667c9.373-9.373 24.569-9.373 33.941 0L285.475 239.03c9.373 9.372 9.373 24.568.001 33.941z"/>
</svg>

Output

import {createElement as e} from 'react'
const C=({title,desc,...props})=>e("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 320 512"},props),title!=null?e("title",null,title):null,desc!=null?e("desc",null,desc):null,e("path",{d:"M285.476 272.971L91.132 467.314c-9.373 9.373-24.569 9.373-33.941 0l-22.667-22.667c-9.357-9.357-9.375-24.522-.04-33.901L188.505 256 34.484 101.255c-9.335-9.379-9.317-24.544.04-33.901l22.667-22.667c9.373-9.373 24.569-9.373 33.941 0L285.475 239.03c9.373 9.372 9.373 24.568.001 33.941z"}))
C.displayName="src/images/chevron-right.svg"
export default C

Usage

import Chevron from './images/chevron-right.svg';

const App = () => (
    <div>
        Hello icon <Chevron height={16} />
    </div>
)

webpack.config.js


const babelLoader = {
    loader: 'babel-loader',
    options: {
        cacheDirectory: true,
    },
};

const webpackConfig = {
    module: {
        rules: [
            {
                test: /\.jsx?$/,
                use: babelLoader,
            },
            {
                test: /\.svg($|\?)/i,
                use: [babelLoader, 'svg-to-react-webpack-loader'],
            },
            ...

TypeScript Support

Drop this in a .d.ts file:

declare module "*.svg" {
    const content: React.FunctionComponent<React.SVGProps<SVGSVGElement> & { title?: string, desc?: string }>;
    export default content;
}

Prior Art

These names were already registered on npm 😢 No code was borrowed and no comparison is provided.

License

MIT