Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Barrel MeNew to Visual Studio Code? Get it now.
Barrel Me

Barrel Me

Arturo Grau

|
1 install
| (1) | Free
Generate Dart barrel files easily for Flutter and Dart projects
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Barrel Me 🛢️

A Visual Studio Code extension for Dart and Flutter projects that makes creating barrel files effortless.

Features

✨ Easy Barrel File Generation: Right-click on any folder to create a barrel file with all Dart exports.

🏗️ Hierarchical Barrel Generation: Optionally create barrel files in each subfolder, with the parent exporting subfolder barrels for better organization.

⚙️ Customizable: Configure which folders and files to exclude from barrel generation.

🔄 Smart Detection: Automatically excludes existing barrel files and main.dart.

🚀 Zero Configuration: Automatically uses the folder name as the barrel filename - just right-click and go!

🛡️ Conflict Prevention: Detects files with the same name as folders and creates {name}_barrel.dart instead of overwriting your code.

🧩 Part File Support: Automatically detects and handles Dart's part/part of system - only exports main files, never part files.

🔄 Import Migration: After creating barrels, optionally migrate existing imports to use the new barrel file automatically.

Usage

Creating a Barrel File

  1. Right-click on a folder in your Dart or Flutter project
  2. Select "Create Barrel" from the context menu
  3. Done! The barrel file(s) are created automatically using the folder name

The extension will:

  • Scan the selected folder for .dart files
  • Exclude main.dart and existing barrel files
  • Generate barrel file(s) with all necessary exports:
    • Non-recursive mode (default): Single barrel file exporting only files in the current directory (subdirectories ignored)
    • Recursive mode: Hierarchical barrels in each subfolder + parent barrel that exports the subfolder barrels
  • Open the barrel file for you to review

Example

If you have the following structure:

lib/features/auth/
  ├── login_page.dart
  ├── signup_page.dart
  ├── widgets/
  │   ├── auth_button.dart
  │   └── auth_form.dart
  └── models/
      └── user.dart

Hierarchical Barrel Mode (default)

Right-click on auth/ → "Create Barrel":

This creates hierarchical barrel files:

auth/models/models.dart:

export 'user.dart';

auth/widgets/widgets.dart:

export 'auth_button.dart';
export 'auth_form.dart';

auth/auth.dart:

export 'login_page.dart';
export 'models/models.dart';
export 'signup_page.dart';
export 'widgets/widgets.dart';

This hierarchical approach:

  • ✅ Creates a barrel file in each subfolder (only if it has 2+ main files)
  • ✅ Parent barrel exports subfolder barrels (not individual files)
  • ✅ Better organization for large codebases
  • ✅ Each module can be imported independently
  • ✅ Smart conflict resolution: If a file has the same name as its folder, the barrel is named {folder}_barrel.dart
  • ✅ Single-file optimization: Subfolders with only one main file are exported directly (no barrel created)
  • ✅ Part file handling: Automatically excludes part files - only main files are exported

Non-Recursive Mode (optional)

To create a single flat barrel file without hierarchical structure, disable recursive mode:

{
  "barrelMe.recursive": false
}

Right-click on auth/ → "Create Barrel":

Generated auth/auth.dart:

export 'login_page.dart';
export 'signup_page.dart';

This creates a single barrel file that exports only files in the current directory - subdirectories are ignored.

Smart Conflict Resolution

If a subfolder contains a file with the same name as the folder (e.g., models/models.dart with actual code), the extension automatically creates the barrel as {folder}_barrel.dart to prevent overwriting your code:

Example:

auth/models/
  ├── models.dart      (your actual code)
  └── user.dart

Generated auth/models/models_barrel.dart:

export 'models.dart';
export 'user.dart';

Parent auth/auth.dart:

export 'models/models_barrel.dart';

Part File Support

The extension intelligently handles Dart's part and part of system. Part files are automatically excluded from barrel exports - only the main file is exported.

Example:

models/
  ├── user.dart           (main file with 'part' directives)
  ├── user.g.dart         (part file with 'part of user.dart')
  └── user.freezed.dart   (part file with 'part of user.dart')

Generated models/models.dart:

export 'user.dart';  // Only the main file, not the parts

Optimization: If a subfolder only has one main file (even with multiple part files), no barrel is created - the main file is exported directly in the parent barrel.

Automatic Naming

When you press Enter without typing a name, the extension automatically converts the folder name to follow Dart naming conventions (snake_case):

Folder Name Generated Barrel
auth auth.dart
AuthPages auth_pages.dart
user-profile user_profile.dart
shopping_cart shopping_cart.dart

You can always override this by typing a custom name before pressing Enter.

Import Migration

After creating a barrel file, the extension will ask if you want to migrate existing imports. This feature automatically:

Before migration:

// feature/user_profile.dart
import '../auth/login_page.dart';
import '../auth/signup_page.dart';
import '../auth/models/user.dart';

After migration:

// feature/user_profile.dart
import '../auth/auth.dart';  // Single import!

How it works:

  1. Creates your barrel file(s)
  2. Shows prompt: "🔄 Migrate existing imports to use the new barrel file?"
  3. If you click "Yes", scans all Dart files in your workspace
  4. Finds imports from the barrel folder
  5. Replaces them with a single barrel import
  6. Shows summary: "✅ Migrated X import(s) in Y file(s)"

Benefits:

  • ✅ Automatically updates your entire codebase
  • ✅ Cleaner imports throughout your project
  • ✅ Safe: Only processes relative imports (skips package: and dart:)
  • ✅ Smart: Skips files inside the barrel folder itself

Configuration

You can customize the extension behavior in your VS Code settings:

barrelMe.exclude

Folders to exclude when scanning for Dart files.

Default:

["test", "generated"]

Example:

"barrelMe.exclude": ["test", "generated", ".dart_tool", "build"]

barrelMe.recursive

Enable hierarchical barrel file generation (deep recursion). When enabled:

  • Creates barrel files at all nesting levels
  • Creates a parent barrel that exports the subfolder barrels
  • Each subfolder's barrel exports files only within that subfolder
  • Processes complex nested folder structures

Default: true

Example to disable (flat mode):

"barrelMe.recursive": false

barrelMe.excludeFiles

Files to exclude from barrel exports.

Default:

["main.dart"]

Example:

"barrelMe.excludeFiles": ["main.dart", "app.dart"]

Command Palette

You can also access the barrel creation command from the Command Palette:

  1. Press Cmd+Shift+P (Mac) or Ctrl+Shift+P (Windows/Linux)
  2. Type "Create Barrel"
  3. Press Enter

Note: When using the Command Palette, you'll need to right-click on a folder first.

Requirements

  • Visual Studio Code version 1.80.0 or higher
  • Dart or Flutter project

Installation

From VS Code Marketplace

  1. Open VS Code
  2. Press Cmd+Shift+X (Mac) or Ctrl+Shift+X (Windows/Linux)
  3. Search for "Barrel Me"
  4. Click Install

From VSIX

  1. Download the .vsix file
  2. Open VS Code
  3. Go to Extensions view
  4. Click on the "..." menu
  5. Select "Install from VSIX..."
  6. Choose the downloaded file

Development

Prerequisites

  • Node.js (v18 or higher)
  • npm or yarn

Setup

# Clone the repository
git clone https://github.com/arturograu/barrel_me.git
cd barrel-me

# Install dependencies
npm install

# Compile TypeScript
npm run compile

# Watch for changes
npm run watch

Running the Extension

  1. Press F5 in VS Code to open a new Extension Development Host window
  2. Open a Dart or Flutter project
  3. Right-click on a folder and select "Create Barrel"

Building

# Compile and package
npm run vscode:prepublish
vsce package

Contributing

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

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Issues

If you encounter any problems or have suggestions, please file an issue on the GitHub repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Enjoy creating barrel files! 🛢️

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft