Are you an LLM? You can read better optimized documentation at /zh\guide\usage\linter\rules\oxc\no-barrel-file.md for this page in Markdown format
oxc/no-barrel-file 限制类
规则作用
禁止使用包含 export * 语句的 barrel 文件,且模块总数超过阈值。
默认阈值为 100。
为什么不好?
重新导出许多模块的 barrel 文件会显著降低应用程序和打包器的速度。当 barrel 文件导出大量模块时,从中导入会强制运行时或打包器处理所有导出的模块,即使实际上只使用了少数几个。这会导致启动时间变慢和打包体积变大。
参考:
- 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
类型:integer
默认值: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。