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.
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;
barrel.config.js
const barrelConfig = {
dir: [
// For example
'./models', './libs', './components'
]
};
module.exports = barrelConfig;
npx node node_modules/barrel-tool/src/barrel.generator.js
npx node node_modules/barrel-tool/src/barrel.watch.js
"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"
}
Specify the directories that will be included in the barrel.
default:
dir: [
// required
]
dir: [
'./models', './utils', './components'
]
Specify the name of the barrel file. Recommended to use index.ts
default:
saveAs: 'index.ts'
Specify if you want to use semicolon at the end of each line.
default:
useSemicolon: false
useSemicolon: true
Specify if you want to use extension at the end of each line.
default:
useExtension: false
useExtension: true
Specify if you want to separate the barrel by files.
default:
separateByFiles: false
separateByFiles: true
Specify if you want to include sub-folders.
default:
subFolders: true
subFolders: false
Soon, we will add exclusions.
barrel.config.js
const barrelConfig = {
dir: [
'./components'
],
subFolders: false,
separateByFiles: true,
useSemicolon: true
}
module.exports = barrelConfig