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

@domeadev/vite-plugin-export-index

v0.1.0

Published

A Vite plugin that automatically generates index files with exports for your directories

Readme

vite-plugin-export-index

A Vite plugin that automatically generates index files with exports for your directories. This plugin watches specified directories and automatically creates/updates index.ts files with export statements based on the files in those directories.

Features

  • 🚀 Automatic Generation: Automatically generates index.ts files with exports
  • 👀 File Watching: Watches for file changes and updates exports in real-time during development
  • 🎨 Customizable: Flexible resolver functions to control export generation
  • 📝 Custom Banners: Add custom headers to generated files
  • 🔧 TypeScript Support: Full TypeScript support with proper type definitions

Installation

npm

npm install @domeadev/vite-plugin-export-index

pnpm

pnpm add @domeadev/vite-plugin-export-index

yarn

yarn add @domeadev/vite-plugin-export-index

Usage

Basic Setup

Add the plugin to your vite.config.ts:

import { defineConfig } from "vite";
import { exportIndex } from "@domeadev/vite-plugin-export-index";

export default defineConfig({
  plugins: [
    exportIndex({
      options: [
        {
          dir: "src/components",
          resolver: ({ basename, extname }) => {
            if (extname === "tsx" || extname === "ts") {
              return `export { default as ${basename} } from './${basename}';`;
            }
            return null;
          },
        },
      ],
    }),
  ],
});

Advanced Configuration

import { defineConfig } from "vite";
import {
  exportIndex,
  defineResolver,
} from "@domeadev/vite-plugin-export-index";

const componentResolver = defineResolver(({ basename, extname, name }) => {
  // Skip non-TypeScript files
  if (!["ts", "tsx"].includes(extname)) return null;

  // Skip test files
  if (basename.includes(".test") || basename.includes(".spec")) return null;

  // Generate named exports for components
  if (extname === "tsx") {
    return `export { default as ${basename} } from './${basename}';`;
  }

  // Generate barrel exports for utilities
  if (extname === "ts") {
    return `export * from './${basename}';`;
  }

  return null;
});

export default defineConfig({
  plugins: [
    exportIndex({
      options: [
        {
          dir: "src/components",
          dest: "src/components/index.ts", // Optional: custom destination
          banner:
            "// Components barrel export\n// Auto-generated - do not edit manually\n\n",
          resolver: componentResolver,
        },
        {
          dir: "src/utils",
          resolver: ({ basename, extname }) => {
            if (extname === "ts") {
              return `export * from './${basename}';`;
            }
            return null;
          },
        },
      ],
      showLogs: true, // Enable/disable logging (default: true)
    }),
  ],
});

API Reference

exportIndex(config)

Main plugin function.

Parameters

  • config.options - Array of export options
  • config.showLogs - Whether to show logs (default: true)

ExportOption

Configuration for each directory to watch:

interface ExportOption {
  /** Custom banner/header for the generated file */
  banner?: string;

  /** Directory to watch for files */
  dir: string;

  /** Destination file path (default: `${dir}/index.ts`) */
  dest?: string;

  /** Function to resolve export statements for each file */
  resolver: (variables: {
    /** Relative directory path from src */
    dir: string;
    /** Full filename with extension */
    name: string;
    /** Filename without extension */
    basename: string;
    /** File extension without dot */
    extname: string;
  }) => string | null | undefined | false;
}

defineResolver(resolver)

Helper function for better TypeScript support when defining resolvers.

Examples

React Components

{
  dir: 'src/components',
  resolver: ({ basename, extname }) => {
    if (extname === 'tsx') {
      return `export { default as ${basename} } from './${basename}';`
    }
    return null
  }
}

Utility Functions

{
  dir: 'src/utils',
  resolver: ({ basename, extname }) => {
    if (extname === 'ts' && !basename.includes('.test')) {
      return `export * from './${basename}';`
    }
    return null
  }
}

Custom Types

{
  dir: 'src/types',
  resolver: ({ basename, extname }) => {
    if (extname === 'ts') {
      return `export type * from './${basename}';`
    }
    return null
  }
}

How It Works

  1. Directory Watching: The plugin watches specified directories for file changes
  2. File Analysis: When files are added/removed, the resolver function is called for each file
  3. Export Generation: The resolver determines what export statement to generate (or skip)
  4. Index File Update: The plugin writes all export statements to the index file
  5. Real-time Updates: During development, changes trigger automatic regeneration

Contributing

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

License

MIT