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 🙏

© 2026 – Pkg Stats / Ryan Hefner

asset-webpack

v6.0.0

Published

asset-bundle integration for WebPack

Readme

asset-webpack

A WebPack plugin that combines all your SVG assets into a asset-provider compatible bundle.

Table of Contents

Install

npm install --save asset-webpack

Usage

Import the loader in to your webpack.config.js:

import SVGBundler from 'asset-webpack';

const bundle = new SVGBundler('bundle.svgs', { /* opts */ });

The first argument is the name the bundle. It should be single file name, and it will be placed in the output directory that you specified in the WebPack configuration. The filename supports the following (template) replacements:

  • [hash] Will be replaced with a MD5 hash of the resulting bundle.

The second argument is an options object that allows you to further configure the plugin, and the bundle system. The following options are supported:

  • namespace Should we use the folder structure of the assets as namespaces, defaults to false.
  • root Location of the root directory that used to generate the namespaces.
  • bundler Options that will be passed in to the asset-bundle constructor.
  • modify An object where the key is the name of the modifer and the value the function that does the modification. This will be passed in to bundle#modify.
  • plugins Plugins that need to be assigned to the asset-bundle instance. The plugins option should be an Array of arrays which is spread on the bundle#plugin method.
  ...
  namespace: true,
  bundler: {
    multipass: true,
  },
  modify: {
    color: function () { .. }
  },
  plugins: [
    [Constructor, { options }, args, etc],
    [Constructor, { options }, args, etc]
  ]
  ...

Configure the loader

First we need to ensure that .svg files are handled by the bundle. Update the module rules/loaders to contain the following:

module: {
  rules: [
    { test: /\.svg$/, use: bundle.loader() }
  ]
}

The bundle.loader() will return a correctly pre-configured loader so we can replace the contents of the file, and introduce it into the svgs bundle.

Insert the bundle instance as plugin

Last but not least, pass the created bundle instance into the plugin array of your webpack.config.js:

{
  ...,
  plugins: [ bundle ]
}

And done, you've completed the following steps:

  • Created a new Bundle instance
  • Used it's loader method to configure the correct loader
  • Passed the instance into the plugin array

Producing a bundle

Create the entry file that requires the SVG assets:

require('./file.svg');
require('./another.svg');
require('./more.svg');

In addition to producing the bundled SVG, we've also rewritten the contents of the required file. The file will now return the name of your SVG how it's stored inside the bundle.

import Provider, { Asset } from 'asset-provider';
import React, { Component } from 'react';
import upload from './upload.svg';
import file from './file.svg';

export default class Example extends Component {
  render() {
    return (
      <Provider uri='http://url.com/bundle.svgs'>
        <div>
          <h1>Upload <Asset name={ file } /></h1>

          <label>
            Upload file: <input type='file' name='file' />
          </label>

          <button> Upload <Asset name={ upload } /></button>
        </div>
      </Provider>
    );
  }
}

License

MIT