Our review
Defines conventions for module exports and barrel files in TypeScript projects, emphasizing named exports and avoiding wildcard re-exports for better tree-shaking.
Strengths
- Optimizes tree-shaking by using named exports.
- Clear barrel file structure with section comments.
- Allows namespace exports for compound components as an exception.
- Enforces consistency across the codebase.
Limitations
- Requires discipline to maintain alphabetical order within sections.
- May be overly strict for small projects where wildcard exports are harmless.
- Not applicable to projects using CommonJS or older bundlers.
Use when organizing a large TypeScript project with multiple modules to ensure efficient bundling and clear export interfaces.
Avoid for small projects or when rapid prototyping where the overhead of maintaining barrel files is not justified.
Security analysis
SafeThis skill is a static style guide for TypeScript export patterns. It contains no executable commands, network operations, or file system modifications. There is no risk of executing harmful actions.
No concerns found
Examples
Create a barrel index.ts file in the components directory following the named exports convention. Group exports by sections: Components, Hooks, Types. Each export should be on its own line, sorted alphabetically within sections. Do not use wildcard exports. If there are compound components like Dialog or Menu, use export * as Name for them.Refactor the barrel file at src/ui/index.ts to remove all default exports and replace them with named exports. Ensure that source files use named exports instead of default exports. Also replace any export * from wildcards with explicit named exports. Maintain section comments and alphabetical order.Add an export for a new component named 'Button' with its props type 'ButtonProps' in the existing barrel file at src/components/index.ts. Insert it in the Components section in alphabetical order.name: exports description: Export patterns and barrel file conventions. Use when creating/modifying index.ts files or organizing module exports.
Exports & Barrel Files
Standards for module exports and barrel files in the portal app.
Core Principle
Named exports only. No flat wildcards. No default exports in barrels.
Turbopack and modern bundlers handle named exports better for tree-shaking. Flat wildcard export * forces bundlers to include everything and breaks cache invalidation.
Exception: export * as Name is allowed for compound components (Dialog, Menu, etc.) to create namespaces.
Barrel File Structure
Every barrel file follows this structure:
/* eslint-disable */
// Section Name
export { Thing, type ThingProps } from "./thing";
export { Other } from "./other";
// Another Section
export { More } from "./more";
Rules
- ESLint disable at top - Barrel files intentionally re-export
- Section comments - Group related exports with
// Section Name - Alphabetical within sections - Sort exports alphabetically within each group
- Types with values - Export types alongside their values:
export { Foo, type FooProps } - One line per file - Each source file gets one export line
Section Naming
Use these section names consistently:
| Section | Contents |
| ------------ | --------------------------------- |
| Components | React components |
| Hooks | Custom React hooks |
| Types | Type-only exports |
| Constants | Const values, enums, config |
| Utilities | Pure functions |
| Context | React context providers/consumers |
| Mutations | Data mutation hooks (React Query) |
| Queries | Data fetching hooks (React Query) |
| Store | Zustand/state stores |
Examples
Component Barrel
/* eslint-disable */
// Components
export { ActionCard } from "./action-card";
export { ActionList } from "./action-list";
export { ActionPicker } from "./action-picker";
State/Domain Barrel
/* eslint-disable */
// Store
export { useNodesSelection, useNodesSelectionArray } from "./store";
// Types
export {
type NodeOwner,
type NodePermissionRow,
type NodeRow,
type NodeWithMeta,
transformNode,
} from "./types";
UI Library Barrel
For compound components (Dialog, Menu, etc.), export as namespaces using export * as:
/* eslint-disable */
// Simple Components
export { Badge, type BadgeProps } from "./badge";
export { Button, type ButtonProps } from "./button";
export { Input, type InputProps } from "./input";
// Compound Components (namespace exports)
export * as Accordion from "./accordion";
export * as Alert from "./alert";
export * as Dialog from "./dialog";
export * as Menu from "./menu";
// Layout
export { AbsoluteCenter } from "./absolute-center";
export { Group } from "./group";
Note: Compound components use export * as Name to create namespaces (e.g., Dialog.Root, Dialog.Content). This is the ONE exception to the "no wildcards" rule - it creates a namespace, not a flat re-export.
What NOT to Do
No Flat Wildcards
// WRONG - flat wildcard re-exports everything
export * from "./button";
export * from "./card";
// RIGHT - named exports
export { Button, type ButtonProps } from "./button";
// RIGHT - namespace export for compound components
export * as Card from "./card";
No Default Exports in Barrels
// WRONG
export { default as Button } from "./button";
// RIGHT - source file should use named export
export { Button } from "./button";
No Aliasing (Unless Necessary)
// WRONG - unnecessary alias
export { Button as ButtonComponent } from "./button";
// RIGHT
export { Button } from "./button";
// OK - resolving actual name conflict
export { ActionList as ActionListComponent } from "./action-list";
No Mixed Concerns
// WRONG - implementations don't belong in barrel
export { Button } from "./button";
export const DEFAULT_SIZE = "md"; // NO - this belongs in a constants file
// RIGHT - barrel only re-exports
export { Button } from "./button";
export { DEFAULT_SIZE } from "./constants";
When to Create a Barrel
Always. Every directory with exportable code gets an index.ts.
Index Files Are ONLY Barrels
An index.ts file must ONLY contain re-exports. No implementations.
If you find an index.ts with actual code (functions, constants, types defined inline), split it up:
- Move implementations to separate files (e.g.,
utils.ts,types.ts,constants.ts) - Make
index.tsa pure barrel that re-exports from those files
// WRONG - index.ts with implementation
export const FOO = "bar";
export function doThing() { ... }
export interface MyType { ... }
// RIGHT - index.ts as pure barrel
export { FOO } from "./constants";
export { doThing } from "./utils";
export type { MyType } from "./types";
Import Conventions
When importing from barrels:
// GOOD - import from barrel
import { Button, Card, Dialog } from "@/components/ui";
import { useNodes, useNodeMutations } from "@/lib/state";
// AVOID - bypassing barrel for public exports
import { Button } from "@/components/ui/button";
// OK - importing internal/non-exported utilities
import { internalHelper } from "@/components/ui/button/helpers";
Instructions
When creating or modifying barrel files:
- Add
/* eslint-disable */at top - Group exports into logical sections with
// Section Name - Use named exports only - no flat
export *(exception:export * as Namefor compound component namespaces) - Sort exports alphabetically within sections
- Include types with their values on same line
- One export statement per source file
Next.js App Router Expert
Development
A skill that turns Claude into a Next.js App Router expert.
README Generator
Development
Creates professional and comprehensive README.md files for your projects.
API Documentation Writer
Development
Generates comprehensive API documentation in OpenAPI/Swagger format.