AutoBarrel is a Visual Studio Code extension that simplifies the creation of barrel files (index.ts
or index.js
) in your TypeScript or JavaScript projects. A barrel file centralizes exports from a directory, making imports easier and cleaner in other files.
- Automatic Barrel File Creation: Creates an
index.ts
orindex.js
file in the selected directory, automatically exporting all modules within that directory. - Subdirectory Support: Detects and handles subdirectories, exporting only the index (
index.ts
orindex.js
) of directories that contain it. - Customizable Settings:
- File Extension: Choose whether to generate barrel files with a
.ts
or.js
extension. - Remove File Extension: Configure whether to remove the file extension from exported files in the barrel file.
- File Extension: Choose whether to generate barrel files with a
- Open Visual Studio Code.
- Go to the Extensions view (square icon in the sidebar).
- Search for AutoBarrel and install it.
- Restart Visual Studio Code if necessary.
- Open the Command Palette (
Ctrl+Shift+P
orCmd+Shift+P
on macOS). - Type
Create Barrel
and run it. - Select the directory where you want to create the barrel file.
- The extension will create an
index.ts
orindex.js
file in the selected directory, automatically exporting all modules in that directory.
You can customize the extension's behavior through VSCode settings. Go to File > Preferences > Settings
(or Code > Preferences > Settings
on macOS) and search for AutoBarrel
.
- Remove File Extension (
autobarrel.removeExtension
): Removes the file extension in export statements.- Type:
boolean
- Default:
true
- Type:
- Use JavaScript (
autobarrel.useJavaScript
): Use.js
extension instead of.ts
for barrel files.- Type:
boolean
- Default:
false
- Type:
{
"autobarrel.removeExtension": true,
"autobarrel.useJavaScript": false
}
Take a look at the changelog of the extension.
Contributions are welcome! Feel free to create issues and Pull Requests.
This project is licensed under the MIT License - see the LICENSE file for details.