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

inject-assets-webpack-plugin

v0.2.3

Published

Inject webpack assets names wherever you want

Downloads

211

Readme

Inject Assets Webpack Plugin

This is a simple but powerful webpack plugin which allows you to inject any webpack-related data to any project files.

Installation

npm install --save-dev inject-assets-webpack-plugin

Basic usage

Imagine you have bundle with hashed js files and you would like to cache them with service worker. To activate new service worker on rebuild you can also inject webpack build hash into service worker.

public/serviceWorker.js example:

// {hash}

var myHostname = '{hostname}';
var filesToCache = ['{bundleFiles}'];
...
var config = require('you-app-config.json');
var InjectAssetsWebpackPlugin = require('inject-assets-webpack-plugin');

var webpackConfig = {
  entry: {
    app: ['./src/app.js'],
    vendor: [
      'react',
      'react-dom',
      'redux',
      'react-redux'
    ],
  },
  output: {
    path: path.join(__dirname, '/public/'),
    filename: 'js/[name].[chunkhash].js',
    publicPath: '/'
  },
  plugins: [
    new InjectAssetsWebpackPlugin({
      filename: 'public/serviceWorker.js'
    },[
      {
        pattern: '{hash}',
        type: 'hash'
      },
      {
        pattern: '{hostname}',
        type: 'value',
        value: config.hostname
      },
      {
        pattern: '{bundleFiles}',
        type: 'chunks',
        chunks: ['app', 'vendor'],
        files: ['.js', '.css'],
        excludeFiles: ['.map'],
        decorator: function(fileNames) {
          return fileNames.join('\', \'');
        } 
      }
    ]),
    ...
  ]
};

You can also inject js and css files into html. It is better to use another plugin like html-webpack-plugin, but if you prefer full control of a process you can use inject-assets-webpack-plugin

public/index.html example:

<head>
  %styles%
</head>
<body>
...

  %scripts%
</body>
  plugins: [
    new InjectAssetsWebpackPlugin({
      filename: 'public/index.html'
    },[
      {
        pattern: '%styles%',
        type: 'chunks',
        chunks: ['app'],
        files: ['.css'],
        excludeFiles: ['.map'],
        decorator: function(fileNames) {
          return fileNames.reduce(function(output, fileName) {
            return output + '<link href="' + fileName + '" rel="stylesheet">';
          }, '');
        }
      },
      {
        pattern: '%scripts%',
        type: 'chunks',
        chunks: ['app', 'vendor'],
        files: ['.js'],
        excludeFiles: ['.map'],
        decorator: function(fileNames) {
          return fileNames.reduce(function(output, fileName) {
            return output + '<script type="text/javascript" src="' + fileName + '"></script>';
          }, '');
        }
      }
    ]),
    ...
  ]

Plugin specification

new InjectAssetsWebpackPlugin(options, [replacements])

options object has the following properties:

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | filename | string | index.html in output webpack dir | Path to a file which content should be replaced. Can be related to project root or absolute. | | event | string | done | Webpack plugin event hook name which handles replacement. Can be one of done, compile, emit. |

each replacement object has the following properties:

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | pattern | string or RegExp | none | Search pattern. All found entries will be replaced by replacement. | | type | string | chunks | Define the replacement type. Can be one ofhash - found entries will be replaced by webpack build hash,value - found entries will be replaced by the following value,chunks - found entries will be replaced by matched asset chunks file names. | | value | string or number | none | Used only for value type. Defines replacement value. | | chunks | array | all chunks | Used only for chunks type. Defines a list of webpack chunks names processed by plugin. Use all chunks if not specified. | | excludeChunks | array | none | Used only for chunks type. Defines a list of webpack chunks names excluded from processing by plugin. | | files | string or RegExp | none | Used only for chunks type. Only files matched by that puttern will be used as replacement. | | excludeFiles | string or RegExp | none | Used only for chunks type. All files matched by that puttern will be excluded from replacement. | | decorator | function(array) | none | Used only for chunks type. Used to decorate replacement file names |

Licence

MIT