This rule aims to avoid importing barrel files that lead to loading large module graphs. This rule is different from the avoid-barrel-files
rule, which lints against authoring barrel files. This rule lints against importing barrel files.
Examples of incorrect code for this rule:
// If `foo` is a barrel file leading to a module graph of more than 20 modules
export { foo } from 'foo';
This rule takes an optional configuration:
{
"rules": {
"barrel-files/avoid-importing-barrel-files": [
2,
{
"maxModuleGraphSizeAllowed": 40,
"amountOfExportsToConsiderModuleAsBarrel": 5,
"exportConditions": ["node", "import"],
"mainFields": ["module", "main", "browser"],
"extensions": [".js", ".ts", ".json", ".node"],
"tsconfig": {
"configFile": "./tsconfig.json",
"references": []
}
}
]
}
}
The rule can accept an alias
option whose value can be an object that matches Webpack's resolve.alias configuration.
// .eslintrc.cjs
const path = require('path')
module.exports = {
// ...
"rules": {
"barrel-files/avoid-importing-barrel-files": [
2,
{
alias: {
// "@/foo/bar.js" => "./src/foo/bar.js"
"@": [path.resolve(".", "src")]
}
}
]
}
}