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

barrelize

v1.6.6

Published

Automatically generating index (barrel) files

Readme

Barrelize

🚀 A modern, lightweight and efficient tool for automatically generating index (barrel) files in your JavaScript and TypeScript projects.

Barrelize simplifies module exports by creating clean, centralized index.js or index.ts files, reducing boilerplate and improving project organization.

NPM Version GitHub License

Barrelize in action

Features

  • Automatic Barrel Generation: Scans directories and creates index files with exports for all modules.
  • TypeScript Support: Seamlessly works with TypeScript projects, preserving type safety.
  • Customizable: Configure file patterns, ignore specific files, or customize export styles (named, default, or both).
  • Recursive: Optionally generate barrels for nested directories.
  • CLI & API: Use via command line for quick setups or integrate programmatically in your build scripts.
  • Smart Export Control: Fine-grained control over what gets exported and how:
    • Export specific members, namespaces, or use regex patterns
    • Support for custom export names and transformations
    • Support for asterisk (*) exports
    • Flexible export path manipulation
  • Flexible Path Handling: Replace patterns in export paths using string or regular expressions
  • Customizable Formatting: Control bracket spacing, quotes, semicolons, and newlines

Why Use Barrelize?

  • Save Time: Eliminate manual creation and maintenance of barrel files.
  • Cleaner Imports: Simplify import statements with a single entry point for each directory.
  • Scalable: Ideal for large projects with complex folder structures.

Installation

npm install --save-dev barrelize

Quick Start

  1. Initialize configuration (optional):
npx barrelize init
  1. Generate barrel files:
npx barrelize

CLI Commands

barrelize init [config path]

Creates a .barrelize configuration file in your project.

npx barrelize init                # Creates .barrelize in current directory
npx barrelize init barrelize.json # Creates config at specified path

barrelize [config path]

Generates barrel (index) files based on your configuration. The tool will:

  • Create or update index files in specified directories
  • Export all matching files based on include/exclude patterns
  • Order exports according to your configuration
  • Apply path replacements
  • Format exports according to your style preferences
npx barrelize                # Uses default .barrelize config
npx barrelize custom.json    # Uses specified config file
npx barrelize --watch        # Generate and watch for changes

Options:

  • -w, --watch: Watch for changes and regenerate barrel files automatically

Configuration

Create a .barrelize file in your project root. The configuration file uses JSON5 format, which supports comments and is more flexible than standard JSON:

{
  "$schema": "node_modules/barrelize/schema.json",
  // Global formatting settings
  "bracketSpacing": true, // Add spaces between brackets in exports (default: true)
  "singleQuote": true, // Use single quotes for exports (default: true)
  "semi": true, // Add semicolons after exports (default: true)
  "insertFinalNewline": true, // Add newline at end of file (default: true)

  // Configure multiple barrels
  "barrels": [
    {
      // Root directory to start from (default: "")
      "root": "src",
      // Name of the index file (default: "index.ts")
      "name": "index.ts",
      // Files to include in the barrel (default: ["**/*.ts"])
      "include": ["**/*.ts"],
      // Files to exclude from the barrel (default: [])
      "exclude": ["**/*.test.ts"],
      // Optional ordering of exports (default: [])
      "order": ["types", "constants", "utils"],
      // String/regex patterns to find and replace in export paths
      "replace": {
        "/\\.ts$/": "" // Remove .ts extension from paths
      },
      // Export configuration for different file patterns
      "exports": {
        // Glob pattern exports file with string or regular expression patterns
        "**/*.ts": [
          "* as lib", // Export all as namespace
          "/(.+)Config$/ as $1LibConfig", // Rename exports matching pattern
          "util" // Export specific member
        ]
      },
      // Override global formatting settings per barrel
      "bracketSpacing": true,
      "singleQuote": true,
      "semi": true,
      "insertFinalNewline": true
    }
  ]
}

Example

Before:

src/
  ├── types.ts
  ├── constants.ts
  ├── utils.ts
  └── components/
      ├── Button.tsx
      └── Input.tsx

After running barrelize:

src/
  ├── types.ts
  ├── constants.ts
  ├── utils.ts
  ├── index.ts           # New!
  └── components/
      ├── Button.tsx
      └── Input.tsx

Generated src/index.ts:

export * from './types';
export * from './constants';
export * from './utils';
export * from './components/Button.tsx';
export * from './components/Input.tsx';

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT © Nizami