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

@chipzhang/webpack-asset-attributes-plugin

v0.1.1

Published

Add custom attributes to the asset tags in the generated HTML by html-webpack-plugin

Readme

Add custom attributes to the asset tags in the generated HTML by html-webpack-plugin

Overview

This is a webpack plugin, that adds custom attributes (i.e. onload) to the JS / CSS asset tags generated by html-webpack-plugin. This plugin only handles statically loaded assets, rather than lazy loaded assets (i.e. via import('file') syntax). Supports webpack v4 + html-webpack-plugin v4, or webpack v5 + html-webpack-plugin v5. This package has built-in TypesScript support.

Install

npm i @chipzhang/webpack-asset-attributes-plugin

Note this will not install webpack or html-webpack-plugin automatically.

Options

scriptAttribs

A key-value object representing the custom attributes to add to the JS asset tags. Values can be string or boolean, and will be automatically escaped. For example:

{onload: 'console.log("JS Asset loaded", this)', defer: true}

styleAttribs

A key-value object representing the custom attributes to add to the CSS asset tags. Values can be string or boolean, and will be automatically escaped. For example:

{onload: 'console.log("CSS Asset loaded", this)', disabled: true}

Example Usage

const HTMLPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const {AssetAttributesPlugin} = require('@chipzhang/webpack-asset-attributes-plugin')

const assetAttributesPlugin = new AssetAttributesPlugin({
  scriptAttribs: {onload: 'console.log("JS Asset loaded", this)', defer: true},
  styleAttribs: {onload: 'console.log("CSS Asset loaded", this)', disabled: true},
})

module.exports = {
  /* your webpack configs */
  plugins: [new HTMLPlugin(), new MiniCssExtractPlugin(), assetAttributesPlugin],
  module: {
    rules: [
      /* loaders for other file extensions */
      {
        test: /\.css$/i,
        use: [MiniCssExtractPlugin.loader, 'css-loader'],
      },
    ],
  },
}

In your webpack config file, first add plugin html-webpack-plugin, to generate the HTML file. Then configure this plugin (@chipzhang/webpack-asset-attributes-plugin), to add custom attributes to the JS / CSS asset tags. You may need mini-css-extract-plugin to generate separate CSS files instead of inlining styles in JS files.

For the above example, the generated HTML may look like:

<html>
  <head>
    <!-- other head tags -->
    <script defer src="example.js" onload='console.log("JS Asset loaded", this)'></script>
    <link href="example.css" rel="stylesheet" onload='console.log("CSS Asset loaded", this)' disabled />
  </head>
  <body>
    <!-- body tags -->
  </body>
</html>

License

GNU AFFERO GENERAL PUBLIC LICENSE Version 3