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

kuyin-webpack-plugins

v1.7.2

Published

custom webpack, enhanced-resolve plugins

Downloads

9

Readme

[toc]

介绍

本项目主要包含一些自定义 webpack 和 enhanced-resolve 插件,方便跨项目共享构建插件

命名约定

所有 webpack 插件都以 webpackplugin 结尾,所有 enhanced-resolve 插件都以 resolveplugin 结尾

插件列表

InsertHbsCodeWebpackPlugin

依赖于 html-webpack-plugin,主要作用是在最终生成的 html 文档中加入一段自定义代码片段。

  • 使用场景 比如说我们可以区分环境在最终生成的 html 文件里面添加不同的数据,开发环境填充 mock 数据,生产环境填充占位符,丢给 node 层做服务端渲染的时候填充数据
  • 使用示例
// 需要预先在模板html中放置此占位符
const placeholder='placeholder';
const hbsCode='<script>console.log("hello world")</script>'

module.exports={
    plugins: {
      new InsertHbsCodeWebpackPlugin({
        placeholder,
        hbsCode,
      });
    }
}

ReplaceModuleResolvePlugin

构建时动态替换 module

  • 使用场景 区分环境编译不同的依赖包,比如说我们基于 soundmanager2 写个播放器组件,写代码的时候可以直接引用 soundmanager2 包(源码,包含了调试功能),然后在生产环境构建配置中使用此插件动态将 soundmanager2 替换为 soundmanager2-nodebug-jsmin.js

  • 使用示例

module.exports = {
  resolve: {
    plugins: [
      new ReplaceModuleResolvePlugin({
        sourceModule: 'soundmanager2',
        destModule: 'soundmanager2-nodebug-jsmin.js',
      }),
    ],
  },
};

DefineGlobalsWebpackPlugin & FallbackResolvePlugin

找不到某些文件的时候使用默认路径查找文件

  • 使用场景 比如说我们写了个 vue 组件包,组件引用了样式和图片文件,然后我们在业务端使用的时候借助此插件组合可以实现业务端未提供样式表和图片的时候直接使用组件包里面默认的样式表和图片

  • 使用示例

module.exports = {
  plugins: [DefineGlobalsWebpackPlugin],
  resolve: {
    plugins: [
      new FallbackResolvePlugin({
        pattern: /~?@.*\.(less|css|scss|sass|png|jpg|gif|jpeg)/,
        fallbackPath: path.resolve(__dirname, '../ring-component/src'),
      }),
    ],
  },
};

ChangeAssetsPathWebpackPlugin

webpack 构建完成后修改 assets 输出路径

  • 使用场景 使用 vue-cli 构建 vue 项目时如果直接使用 assetsDir 改变 assets 输出路径会导致最终生成的 html 模板文件中的资源路径也发生改变,但是出于某种原因我们可能又不希望最终生成的 html 文件中资源路径发生改变。(比如说做服务端渲染,资源都放在指定路径下)

  • 使用示例

new ChangeAssetsPathWebpackPlugin({
  assetsPath: `../../../ring-proxy/public/`,
  ignore: /index\.(?:html|hbs)/,
}),