{"id":24521855,"url":"https://github.com/dev-pengi/vite-exporter","last_synced_at":"2025-06-28T21:34:15.088Z","repository":{"id":268895277,"uuid":"896233939","full_name":"dev-pengi/vite-exporter","owner":"dev-pengi","description":"A vite plugin that auto-generate index files to make exports/imports more readable and centralized","archived":false,"fork":false,"pushed_at":"2025-06-01T23:18:58.000Z","size":131,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-02T08:38:06.126Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dev-pengi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-29T20:53:17.000Z","updated_at":"2025-05-27T05:03:15.000Z","dependencies_parsed_at":"2025-04-14T11:50:34.799Z","dependency_job_id":"e343bb05-9a3f-4a96-94ce-a4f817c348eb","html_url":"https://github.com/dev-pengi/vite-exporter","commit_stats":null,"previous_names":["dev-pengi/vite-exporter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dev-pengi/vite-exporter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-pengi%2Fvite-exporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-pengi%2Fvite-exporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-pengi%2Fvite-exporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-pengi%2Fvite-exporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dev-pengi","download_url":"https://codeload.github.com/dev-pengi/vite-exporter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-pengi%2Fvite-exporter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262502960,"owners_count":23321177,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-22T03:16:43.927Z","updated_at":"2025-06-28T21:34:15.073Z","avatar_url":"https://github.com/dev-pengi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Vite Exporter Plugin\n\nThe Vite Exporter Plugin automatically generates `index.ts` files that exports all modules from a specified directory. This is useful for organizing and managing your exports in a Vite project.\n\n## Installation\n\n```sh\nnpm install vite-exporter\n# or\nyarn add vite-exporter\n```\n\n## Quick Start\n\n```typescript\n// vite.config.ts\nimport { defineConfig } from \"vite\";\nimport { generateIndexPlugin } from \"vite-exporter\";\n\nexport default defineConfig({\n  plugins: [\n    generateIndexPlugin({\n      dirs: [\"src/components\", \"src/utils\"],\n    }),\n  ],\n});\n```\n\nfile changes will be detected and the index.ts file will be updated automatically.\n\n## Configuration\n\n### Basic Configuration\n\n```typescript\nimport { generateIndexPlugin, LogLevel, ProcessingMode } from \"vite-exporter\";\n\nexport default defineConfig({\n  plugins: [\n    generateIndexPlugin({\n      dirs: [\"src/components\", \"src/utils\"], // Required: directories to process\n      extensions: [\".ts\", \".tsx\", \".js\", \".jsx\"], // File extensions (default shown)\n      debounceMs: 2000, // Debounce timing (default: 2000)\n      logLevel: LogLevel.DEBUG, // Log verbosity (default: INFO)\n      mode: ProcessingMode.ExportsOnly, // Processing mode (default: ExportsOnly)\n    }),\n  ],\n});\n```\n\n### Advanced Per-Directory Configuration\n\nYou can now specify different matching, exclusion patterns, and processing modes for each directory:\n\n```typescript\ngenerateIndexPlugin({\n  dirs: [\n    // Simple string format (uses global settings)\n    \"src/utils\",\n\n    // Advanced configuration with per-directory settings\n    {\n      dir: \"src/components\",\n      match: [\"**/*.tsx\", \"**/*.ts\"], // Only include TypeScript files\n      exclude: [\"**/*.test.*\", \"**/*.stories.*\"], // Exclude test and story files\n      mode: ProcessingMode.ExportsOnly, // Only export files that have exports\n    },\n    {\n      dir: \"src/api\",\n      match: \"endpoints/**/*\", // Only include files in endpoints subdirectory\n      exclude: [\"**/*.mock.ts\"], // Exclude mock files\n      mode: ProcessingMode.ExportsAndImports, // Export files with exports, import others for side effects\n    },\n    {\n      dir: \"src/setup\",\n      mode: ProcessingMode.ImportAll, // Import all files (exports + side effects)\n    },\n  ],\n  logLevel: LogLevel.DEBUG,\n});\n```\n\n### Processing Modes\n\nThe plugin supports three processing modes that determine how files without exports are handled:\n\n```typescript\nenum ProcessingMode {\n  ExportsOnly = \"exports-only\", // Only export files that have exports - ignores files with no exports\n  ExportsAndImports = \"exports-and-imports\", // Export files with exports, import files without exports for side effects\n  ImportAll = \"import-all\", // Import all files - exports for files with exports, side-effect imports for files without\n}\n```\n\n#### ExportsOnly (default)\n\n- Only includes files that have exports\n- Files without exports are ignored\n- Clean, minimal index files\n\n#### ExportsAndImports\n\n- Includes files with exports as exports\n- Includes files without exports as side-effect imports\n- Useful for libraries with both exports and initialization code\n\n#### ImportAll\n\n- Includes all files that match patterns\n- Files with exports become exports\n- Files without exports become side-effect imports\n- Ensures all code is included and executed\n\n### Pattern Matching\n\nThe plugin uses [minimatch](https://www.npmjs.com/package/minimatch) for pattern matching, supporting:\n\n- `**/*` - Match all files (default)\n- `**/*.tsx` - Match only .tsx files\n- `components/**/*` - Match files in components subdirectory\n- `!**/*.test.*` - Exclude test files (use in exclude array)\n- `*.{ts,tsx}` - Match .ts or .tsx files\n\n## Directory Configuration Options\n\n| Option    | Type                 | Default       | Description                         |\n| --------- | -------------------- | ------------- | ----------------------------------- |\n| `dir`     | `string`             | **Required**  | Directory path to process           |\n| `match`   | `string \\| string[]` | `[\"**/*\"]`    | Glob patterns to include files      |\n| `exclude` | `string \\| string[]` | `[]`          | Glob patterns to exclude files      |\n| `mode`    | `ProcessingMode`     | `ExportsOnly` | How to handle files without exports |\n\n## Global Configuration Options\n\n| Option       | Type                      | Default                          | Description                     |\n| ------------ | ------------------------- | -------------------------------- | ------------------------------- |\n| `dirs`       | `(string \\| DirConfig)[]` | **Required**                     | Directories to process          |\n| `extensions` | `string[]`                | `['.ts', '.tsx', '.js', '.jsx']` | File extensions to include      |\n| `debounceMs` | `number`                  | `2000`                           | Debounce timing in milliseconds |\n| `logLevel`   | `LogLevel`                | `LogLevel.INFO`                  | Logging verbosity level         |\n| `mode`       | `ProcessingMode`          | `ProcessingMode.ExportsOnly`     | Default processing mode         |\n\n## Log Levels\n\n```typescript\nLogLevel.SILENT; // No output\nLogLevel.ERROR; // Only errors\nLogLevel.WARN; // Errors and warnings\nLogLevel.INFO; // Standard info (default)\nLogLevel.DEBUG; // Debug information\nLogLevel.VERBOSE; // All details\n```\n\n## Logging Output\n\nThe new logging system provides beautiful, colored output with timestamps:\n\n```\n15:30:45 [Vite Exporter] INFO    🚀 Plugin initialized with configuration:\n┌─ Configuration\n│ Directories: src/components, src/utils\n│ Extensions: .ts, .tsx, .js, .jsx\n│ Debounce: 1500ms\n│ Log Level: DEBUG\n│ Mode: exports-only\n└─\n\n15:30:45 [Vite Exporter] DEBUG   👀 Watching directory: src/components\n15:30:45 [Vite Exporter] SUCCESS 📝 Generated index.ts in src/components with 5 exports\n15:30:46 [Vite Exporter] DEBUG   ➕ File ADD: src/components/NewComponent.tsx\n15:30:48 [Vite Exporter] SUCCESS 📝 Generated index.ts in src/components with 6 exports\n```\n\n## Generated Files\n\nGiven this structure:\n\n```\nsrc/\n  components/\n    Button.tsx        // export default Button + named exports\n    Input.tsx         // export default Input\n    Select.ts         // only named exports\n    database.init.ts  // no exports, side effects only\n```\n\nWith **ExportsOnly** mode (default):\n\n```typescript\n{\n  dir: 'src/components',\n  mode: ProcessingMode.ExportsOnly\n}\n```\n\nThe plugin generates:\n\n```typescript\n// src/components/index.ts\n// This file is auto-generated by vite-exporter-plugin\nexport { default as Button } from \"./Button\";\nexport * from \"./Button\";\nexport { default as Input } from \"./Input\";\nexport * from \"./Select\";\n// database.init.ts is ignored (no exports)\n```\n\nWith **ExportsAndImports** mode:\n\n```typescript\n{\n  dir: 'src/components',\n  mode: ProcessingMode.ExportsAndImports\n}\n```\n\nThe plugin generates:\n\n```typescript\n// src/components/index.ts\n// This file is auto-generated by vite-exporter-plugin\nexport { default as Button } from \"./Button\";\nexport * from \"./Button\";\nexport { default as Input } from \"./Input\";\nexport * from \"./Select\";\nimport \"./database.init\";\n```\n\n## Configuration Options\n\n| Option       | Type                      | Default                          | Description                     |\n| ------------ | ------------------------- | -------------------------------- | ------------------------------- |\n| `dirs`       | `(string \\| DirConfig)[]` | **Required**                     | Directories to process          |\n| `extensions` | `string[]`                | `['.ts', '.tsx', '.js', '.jsx']` | File extensions to include      |\n| `debounceMs` | `number`                  | `2000`                           | Debounce timing in milliseconds |\n| `logLevel`   | `LogLevel`                | `LogLevel.INFO`                  | Logging verbosity level         |\n| `mode`       | `ProcessingMode`          | `ProcessingMode.ExportsOnly`     | Default processing mode         |\n\n## Examples\n\n### Component Library with Tests\n\n```typescript\ngenerateIndexPlugin({\n  dirs: [\n    {\n      dir: \"src/components\",\n      match: [\"**/*.tsx\", \"**/*.ts\"],\n      exclude: [\"**/*.test.*\", \"**/*.stories.*\", \"**/__tests__/**\"],\n      mode: ProcessingMode.ExportsOnly,\n    },\n  ],\n});\n```\n\n### API Endpoints with Side Effects\n\n```typescript\ngenerateIndexPlugin({\n  dirs: [\n    {\n      dir: \"src/api\",\n      match: \"endpoints/**/*.ts\",\n      exclude: [\"**/*.mock.ts\", \"**/*.spec.ts\"],\n      mode: ProcessingMode.ExportsAndImports, // Include initialization files\n    },\n  ],\n});\n```\n\n### Setup with Initialization Files\n\n```typescript\ngenerateIndexPlugin({\n  dirs: [\n    {\n      dir: \"src/setup\",\n      match: [\"**/*.ts\"],\n      mode: ProcessingMode.ExportsAndImports, // Import files for side effects\n    },\n  ],\n});\n```\n\n### Multiple Directories with Different Rules\n\n```typescript\ngenerateIndexPlugin({\n  dirs: [\n    \"src/utils\", // Simple: match everything\n    {\n      dir: \"src/components\",\n      exclude: [\"**/*.test.*\", \"**/*.stories.*\"],\n    },\n    {\n      dir: \"src/hooks\",\n      match: \"use*.ts\", // Only hook files\n    },\n    {\n      dir: \"src/config\",\n      mode: ProcessingMode.ExportsAndImports, // Side-effect imports\n    },\n  ],\n});\n```\n\n## Troubleshooting\n\n**Enable verbose logging to see everything:**\n\n```typescript\ngenerateIndexPlugin({\n  dirs: [\"src/components\"],\n  logLevel: LogLevel.VERBOSE,\n});\n```\n\n**Common issues:**\n\n- Files not detected → Check `extensions` configuration and `match` patterns\n- Too many updates slow down the build → Increase `debounceMs` value\n- Files excluded → Check `exclude` patterns and ensure they use forward slashes\n- Side-effect imports not working → Use `ProcessingMode.ExportsAndImports` or `ImportAll`\n\n## Migration Guide\n\n### From v1.x to v2.x\n\n```typescript\n// Old (v1.x)\ngenerateIndexPlugin({\n  dirs: [\"src/components\"],\n  excludes: [\"**/*.test.ts\", \"**/*.spec.ts\"], // Global excludes\n  enableDebugging: true,\n  enableDebuggingVerbose: true,\n});\n\n// New (v2.x)\ngenerateIndexPlugin({\n  dirs: [\n    \"src/utils\",\n    {\n      dir: \"src/components\",\n      // not match pattern/patterns so all files will be imported from\n      exclude: [\"**/*.test.ts\", \"**/*.spec.ts\"], // Per-directory excludes\n    },\n  ],\n  logLevel: LogLevel.VERBOSE,\n});\n```\n\n## License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdev-pengi%2Fvite-exporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdev-pengi%2Fvite-exporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdev-pengi%2Fvite-exporter/lists"}