barrel-tool v1.0.33
barrel-tool
Barrel Tool is a utility designed to simplify the generation of "barrels" for your components. Barrels help efficiently organize and export components from multiple files, making their importation more straightforward.
Content
# Installation
Install barrel-tool with npm
npm i -D barrel-tool
or pnpm
pnpm add --save-dev barrel-tool
After that, generate a barrel.config.js
const barrelConfig = {
dir: [
// Add your folder names here: './models', './utils'
]
};
module.exports = barrelConfig;
# Usage
- Add your directory names
barrel.config.js
const barrelConfig = {
dir: [
// For example
'./models', './libs', './components'
]
};
module.exports = barrelConfig;
- Generate barrels
npx node node_modules/barrel-tool/src/barrel.generator.js
- Watch barrels
npx node node_modules/barrel-tool/src/barrel.watch.js
- Add to package.json scripts (optional)
"scripts": {
"barrel-generator": "npx node node_modules/barrel-tool/src/barrel.generator.js",
"barrel-watch": "npx node node_modules/barrel-tool/src/barrel.watch.js"
}
# Settings
- Directory
Specify the directories that will be included in the barrel.
default:
dir: [
// required
]
Example
dir: [
'./models', './utils', './components'
]
- Save as
Specify the name of the barrel file. Recommended to use index.ts
default:
saveAs: 'index.ts'
- Use semicolon
Specify if you want to use semicolon at the end of each line.
default:
useSemicolon: false
Example
useSemicolon: true
- Use extension
Specify if you want to use extension at the end of each line.
default:
useExtension: false
Example
useExtension: true
- Separate by files
Specify if you want to separate the barrel by files.
default:
separateByFiles: false
Example
separateByFiles: true
- Sub-folders
Specify if you want to include sub-folders.
default:
subFolders: true
Example
subFolders: false
Exclusions
Soon, we will add exclusions.
# Example
barrel.config.js
const barrelConfig = {
dir: [
'./components'
],
subFolders: false,
separateByFiles: true,
useSemicolon: true
}
module.exports = barrelConfig
2 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
5 months ago