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
- Right-click on a folder in your Dart or Flutter project
- Select "Create Barrel" from the context menu
- 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:
- Creates your barrel file(s)
- Shows prompt: "🔄 Migrate existing imports to use the new barrel file?"
- If you click "Yes", scans all Dart files in your workspace
- Finds imports from the barrel folder
- Replaces them with a single barrel import
- 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:
- Press
Cmd+Shift+P (Mac) or Ctrl+Shift+P (Windows/Linux)
- Type "Create Barrel"
- 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
- Open VS Code
- Press
Cmd+Shift+X (Mac) or Ctrl+Shift+X (Windows/Linux)
- Search for "Barrel Me"
- Click Install
From VSIX
- Download the
.vsix file
- Open VS Code
- Go to Extensions view
- Click on the "..." menu
- Select "Install from VSIX..."
- 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
- Press
F5 in VS Code to open a new Extension Development Host window
- Open a Dart or Flutter project
- 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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature)
- Commit your changes (
git commit -m 'Add some amazing feature')
- Push to the branch (
git push origin feature/amazing-feature)
- 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! 🛢️