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

webpack-prefetch-plugin

v1.0.0

Published

根据路由 path 进行命名。页面文件打包构建后,会生成 js、css、map 文件,可以过滤掉 map 文件,生成路由 path 和 js、css 文件路径的映射关系。最后组装成 script 脚本,注入 HTML 文件里。页面加载后,就可以根据页面的路由 path,找出对应要加载的 js、css 资源。如果知道用户将要去什么页面,就可以预加载对应页面资源了。如果用户要去的是第三方页面,会进行 DNS 预解析流程。

Readme

项目简介

webpack资源预加载插件,支持:

  • 资源预加载
  • DNS预解析

项目表述

使页面路由打包出来的文件,根据路由 path 进行命名。页面文件打包构建后,会生成 js、css、map 文件,可以过滤掉 map 文件,生成路由 path 和 js、css 文件路径的映射关系。最后组装成 script 脚本,注入 HTML 文件里。页面加载后,就可以根据页面的路由 path,找出对应要加载的 js、css 资源。如果知道用户将要去什么页面,就可以预加载对应页面资源了。如果用户要去的是第三方页面,会进行 DNS 预解析流程。

插件配置

/** 插件默认配置对象
 * @pluginName 自定义插件名称
 * @indectName 输出的映射资源注入到window的变量名称,或者映射文件名字
 * @chunksMapFileFun 自定义输出的映射资源文件的名称
 *   contentHash 用于完整性校验,内容变动都会改变,更好利用缓存
 * @chunkNameFilter chunk输出过滤器:哪些chunk需要生成映射
 *    chunkName 参数为chunk.name
 *    @return boolean true时输出
 * @chunkKeyFun 自定义输出的映射文件中的json对象里的key
 *    chunkName
 *    @return chunkName
 * @injectToHtmlFilter 要注入到的HTML文件的,HTML文件资源过滤器
 *    assetName 打包生成的资源字符串,默认index.html文件
 *    @return boolean true时注入
 * @assetsFilter assets资源输出过滤器
 *    assetUrl
 *    @return boolean true时输出
 * @assetToChunkRegs 把指定资源,映射到指定chunk中,可配置多个筛选项
 *    chunkNameFilter 指定chunkname过滤器
 *    assetNameFilter 指定asset资源过滤器
 *
 * 把包含link-layout的资源放入,包含link的chunkname对应的映射中
 * [{
    chunkNameFilter:(chunkName)=>/link/.test(chunkName),
    assetNameFilter:(assetUrl)=>/link-layout/.test(assetUrl)}]
 */

const defaultOptions = {
  pluginName: "webpack-prefetch-plugin",
  injectName: "_chunks_map",
  chunksMapFileFun: contentHash =>`${this.injectName}.${contentHash}.js`,
  // chunkNameFilter: chunkName => !!chunkName,
  chunkNameFilter: (chunkName)=> chunkName.includes('_'),
  chunkKeyFun: chunkName => chunkName,
  injectToHtmlFilter: assetName => /^index\.html?$/i.test(assetName),
  assetsFilter: assetUrl => {
    // 默认过滤掉chunk对应的映射中的map文件
    return !["map"].includes(path.extname(assetUrl));
  },
  // [{ chunkNameFilter:(chunkName)=>true,assetNameFilter:(assetUrl)=>true}]
  assetToChunkRegs: [],
};