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 🙏

© 2025 – Pkg Stats / Ryan Hefner

content-injector-webpack-plugin

v2.1.0

Published

A flexible Webpack plugin for injecting dynamic content (e.g., version, timestamps) into build assets with precise file matching and position control.

Readme

Content Injector Webpack Plugin 🔌

npm node Downloads License: MIT Coverage

简体中文 | English

内容注入插件,支持灵活的资源修改策略。可轻松添加构建信息、项目版本等通用内容。

✨ 特性

  • 构建时间注入 - 自动添加打包时间戳
  • 🎯 精准定位 - 支持正则/函数匹配文件
  • 📌 位置控制 - 头部/尾部自由选择
  • 🧩 多格式支持 - 原生支持 JS/CSS/HTML 等文本资源
  • 🔐 哈希注入 - 支持基于文件内容的哈希值注入,可配置哈希算法和长度

📦 安装

npm install content-injector-webpack-plugin --save-dev
# 或
yarn add content-injector-webpack-plugin -D
# 或
pnpm install content-injector-webpack-plugin --save-dev

🚀 快速开始

// webpack.config.js
const ContentInjector = require('content-injector-webpack-plugin');

module.exports = {
  plugins: [
    new ContentInjector({
      content: `/*! Build at: ${new Date().toLocaleString()} */\n`,
    }),
  ],
};

⚙️ 配置选项

| 参数 | 类型 | 默认值 | 说明 | | --------------- | ---------------------------------------------------- | --------- | --------------------------------- | | content | string \| () => string \| (hash: string) => string | 必填 | 插入内容,支持动态函数和哈希参数 | | match | RegExp \| (file: string) => boolean | /\.js$/ | 基础匹配条件 | | include | RegExp \| string \| (file: string) => boolean | - | 白名单(优先级高于 match) | | exclude | RegExp \| string \| (file: string) => boolean | - | 黑名单 | | position | 'head' \| 'tail' | 'head' | 内容插入位置 | | injectHash | boolean | false | 是否注入文件哈希值 | | hashAlgorithm | string | md5 | 哈希算法 (如: 'sha1', 'sha256'等) | | hashLength | number | 8 | 哈希值截取长度 |

🌈 高级用法

动态内容生成

new ContentInjector({
  content: () => `/*! 
    Version: ${process.env.APP_VERSION || 'dev'}
    Build: ${new Date().toISOString()}
  */`,
  match: /app\.js$/,
});

多文件类型处理

new ContentInjector({
  content: '<!-- Built with Webpack -->',
  match: /\.(js|css|html)$/,
  exclude: /vendor/,
});

组合条件

new ContentInjector({
  content: '// @generated',
  include: /src\/lib/,
  exclude: (file) => file.includes('test'),
  position: 'tail',
});

哈希值注入

new ContentInjector({
  content: (hash) => {
    return `/*! APP v${require('./package.json').version} ContentHash: ${hash} */\n`;
  },
  match: /\.(js|css)$/,
  injectHash: true,
  hashAlgorithm: 'md5',
  hashLength: 12,
});

🐛 问题

如果您遇到任何问题或有改进建议,请点击这里 Issue Report

📄 许可证

MIT © 2025 flyfox
完整协议见 MIT 文件