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

modular-library

v0.0.5

Published

Plugins for Vite, Rollup, and Rolldown to build modular multi-entry TypeScript libraries.

Readme

modular-library

npm version node version license

modular-library is a utility library for generating modular libraries.

Why

Building a modular library manually is usually tedious and error-prone:

  • keeping package.json exports in sync with your generated files,
  • wiring and maintaining complex glob-based inputs,
  • avoiding output path mistakes when your source tree grows.

modular-library is a zero-config way to generate modular outputs for vite, rollup, and rolldown with predictable structure.

What is a modular library?

A modular library is a library split into small, focused modules instead of one large, monolithic package.

This approach helps you:

  • keep each part of the library easier to understand and maintain,
  • reuse modules independently across projects,
  • reduce coupling between features,
  • improve scalability as the codebase grows,
  • be tree-shakeable so consumers only bundle what they import,
  • expose clear entry points for each public feature or component.

Typical examples of modular libraries include:

  • UI libraries exposing per-component entries (for example @acme/ui/button, @acme/ui/modal),
  • utility libraries exposing per-domain modules (for example @acme/utils/date, @acme/utils/string),
  • SDKs exposing feature-based modules (for example @acme/sdk/auth, @acme/sdk/storage).

With modular-library, the goal is to make the creation of this kind of modular architecture faster and more consistent.

Why this is different from standard library mode

| Approach | Example import | What happens | | --- | --- | --- | | Standard library mode | import { button } from "my-lib"; | Requires evaluating the full package entry. | | Modular library (modular-library) | import button from "my-lib/button"; | Loads only the button module code. |

Before vs. After output

# Before (standard single-entry build)
dist/
  index.js

# After (modular output with modular-library)
dist/
  button.js
  modal.js
  utils/
    formatDate.js

Installation

Node.js requirement: This library supports only Node.js 22 or newer.

npm install modular-library

Usage

modular-library provides dedicated plugins for vite, rollup, and rolldown.

Vite

// vite.config.ts
import { defineConfig } from "vite";
import modularLibrary from "modular-library/vite";

export default defineConfig({
  plugins: [modularLibrary()],
  build: {
    lib: {
      entry: ["src/**/*.ts"],
      formats: ["es"],
    },
  },
});

Rollup

// rollup.config.ts
import modularLibrary from "modular-library/rollup";

export default {
  input: ["src/**/*.ts"],
  output: {
    dir: "dist",
    format: "es",
  },
  plugins: [modularLibrary()],
};

Rolldown

// rolldown.config.ts
import modularLibrary from "modular-library/rolldown";

export default {
  input: ["src/**/*.ts"],
  output: {
    dir: "dist",
    format: "es",
  },
  plugins: [modularLibrary()],
};

Options

All plugin variants support the same options:

| Option | Type | Default | Description | | --- | --- | --- | --- | | relative | string | "src/" | Base path removed from generated output keys. | | glob | GlobOptions | undefined | Options forwarded to fs.globSync. | | transformOutputPath | (outputPath: string, inputPath: string) => string | undefined | Customize each generated output path. |

Example with options:

import modularLibrary from "modular-library/rollup";

export default {
  input: ["src/**/*.ts"],
  output: {
    dir: "dist",
    format: "es",
  },
  plugins: [
    modularLibrary({
      relative: "src/",
      transformOutputPath: (outputPath) => `modules/${outputPath}`,
    }),
  ],
};

Exports tip

To make your package consumable with subpath imports, add an exports map in your package.json:

{
  "exports": {
    "./*": "./dist/*.js"
  }
}

CLI

You can also use modular-library as a CLI with npx.

Check exports

Validate that all package.json export targets exist and are inside your output directory:

npx modular-library check

Named options:

  • --package-json path to package manifest (default: ./package.json)
  • --out-dir output directory to validate against (default: ./dist)

Example:

npx modular-library check --package-json ./package.json --out-dir ./dist

Development

npm install
npm run build
npm test

To test GitHub workflows locally, you can use act.

License

ISC