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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@chrock-studio/unplugin-auto-export

v0.1.5

Published

An auto-export plugin inspired by [`coderhyh/unplugin-auto-export`](https://github.com/coderhyh/unplugin-auto-export) — scans files in specified directories and generates an `index.ts` file to manage module exports in a batch and automated manner.

Downloads

330

Readme

@chrock-studio/unplugin-auto-export

An auto-export plugin inspired by coderhyh/unplugin-auto-export — scans files in specified directories and generates an index.ts file to manage module exports in a batch and automated manner.

With this plugin, you no longer need to manually maintain the index.ts file during development, allowing you to focus solely on writing business code.

Features

  • Based on chokidar v4, fully monitors all file changes in specified folders and updates the index.ts file in real-time
  • Supports custom configurations
    • Specify scan directories: supports glob instances
    • Specify ignored files: matched via regular expressions or functions
    • Specify export files: designated via strings or functions
  • Supports namespace-style exports

Installation

npm install @chrock-studio/unplugin-auto-export

Usage

Assume your project structure is as follows:

src
└── components
    ├── basic.ns          # Files and folders ending with .ns will be treated as namespaces
    │   ├── Card.tsx
    │   └── Progress.tsx
    ├── Button.ts
    └── Input.ts
import { defineConfig } from 'vite'
import autoExport from '@chrock-studio/unplugin-auto-export'

export default defineConfig({
  plugins: [
    autoExport.vite({
      paths: ['src/components'], // Wildcards are not supported, but you can still use glob instances
      ignored: /\/path\/to\/ignore($|\/)/, // Ignore files in specified paths
      output: 'index.ts', // Specify the name of the generated export file
      formatter: (node) => `export * as ${node.$.filename} from './${node.id}'` // Custom export format
    })
  ]
})

After adding the plugin, it will automatically scan all files in the src/components directory and generate an index.ts file in each scanned folder with the following content:

// file: src/components/basic.ns/index.ts
export * from './Card'
export * from './Progress'
// file: src/components/index.ts
export * as Basic from './basic.ns'
export * from './Button'
export * from './Input'

You can import all files in the basic.ns folder via import { Basic } from './components'.

Configuration Options

  • paths: Scan directories
    • required
    • string[]
    • You can use glob (e.g., [...await Array.fromAsync(glob('**/*.js'))]) for matching, but note that this may cause some file changes to not be monitored
    • The recommended approach is to directly specify directories and use ignored to exclude unnecessary files
  • ignored: Ignore files
    • string | RegExp | (val: string, stats?: fs.Stats) => boolean
    • Similar to paths, you can use glob for matching
  • output: Export file
    • string | (node: ChildNode) => string
    • Defaults to index.ts
    • You can dynamically specify the export file name via a function
  • formatter: Export format
    • (node: ChildNode) => string
    • Defaults to import("@chrock-studio/unplugin-auto-export/core/formatter").formatter
    • You can customize the export format via a function
  • debounce: Debounce time
    • number
    • Defaults to 100
    • Used to prevent repeated writes due to frequent file changes
    • You can disable debounce by setting it to 0
  • ...other: Any configuration options supported by chokidar