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

index-loader

v2.2.0

Published

根据 map 文件按需加载需要的脚本

Readme

index-loader

根据 map 文件按需加载需要的脚本

Installation

再运行下面命令创建新项目

npm i --save-dev index-loader

Usage

// webpack.config.js
{
  loader: 'index-loader',
  options: {
    debug: false, // 输出调试信息(全局)
    targets: [
      {
        name: 'antd',
        entryFile: 'path/to/es/antd.js', // 需要是绝对路径
        debug: false,
        additional(src, variables) {
          return `import "xxx.css"`
        }
      }
    ]

  }
}
export type Target = MapTarget | ModuleTarget

interface BaseTarget {
  name: string
  /** 输出替换信息 */
  debug?: boolean
  /** 添加额外的代码 */
  additional?: (src: string, variables: string[], target: ResolvedTarget) => void | string | string[]
  /** 获取依赖的相对路径(注意,最好返回 unix 系统的路径) */
  getRequiredPath?: (
    /**
     * 依赖的变量名,如
     * `import { A } from 'antd'` 中的 "A"
     */
    importedKey: string,
    /**
     * 当前所在的文件
     */
    contextFile: string,
    /**
     * 依赖的文件解析后的路径
     */
    requiredFile: string,
    target: ResolvedTarget
  ) => string
}
export interface MapTarget extends BaseTarget {
  /** 如果没有映射文件,则需要指定 rootDir 和 getRequiredPath */
  mapFile?: string
  mapJson?: {[key: string]: string}
  /** 项目根目录,默认使用 mapFile 的目录 */
  rootDir?: string
}
export interface ModuleTarget extends BaseTarget {
  /** entry file 的 module 类型 */
  entryModule?: 'esnext' | 'commonjs' | 'both'
  entryFile: string
  /** 是否缓存生成的 map 信息 */
  cache?: boolean
}

Map File Example

{
  "Swipe": "swipe/~S",
  "SwipeItem": "swipe/",
  "Marquee": "marquee/~default",
  "TabContainer": "tab-container/",
  "TabContainerItem": "tab-container/",
  "Sticker": "sticker/~default",
  "Indicator": "indicator/~default",
  "Toast": "toast/~default"
}

Support

Changelog

Changelog

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT