Are you an LLM? You can read better optimized documentation at /docs/guide/usage/linter/rules/oxc/no-barrel-file.md for this page in Markdown format
oxc/no-barrel-file Restriction
它的作用
禁止使用桶文件,其中包含 export * 语句, 并且模块总数超过阈值。
默认阈值为 100。
为什么这不好?
重新导出许多模块的桶文件会显著减慢 应用程序和打包器的速度。当一个桶文件导出大量 模块时,从中导入会迫使运行时或打包器处理所有 已导出的模块,即使实际上只使用了其中少数几个。这会导致 更慢的启动时间和更大的 bundle 体积。
参考:
- https://github.com/thepassle/eslint-plugin-barrel-files
- https://marvinh.dev/blog/speeding-up-javascript-ecosystem-part-7
示例
无效:
javascript
export * from "foo"; // 其中 `foo` 加载了一个包含 100 个模块的子树
import * as ns from "foo"; // 其中 `foo` 加载了一个包含 100 个模块的子树有效:
javascript
export { foo } from "foo";配置
此规则接受一个包含以下属性的配置对象:
threshold
type: integer
default: 100
通过 export * 可以重新导出的最大模块数量, 超过该数量后将触发此规则。
如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"oxc/no-barrel-file": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"oxc/no-barrel-file": "error",
},
});bash
oxlint --deny oxc/no-barrel-file版本
此规则在 v0.3.0 中新增。
