Skip to content

noBarrelFile

诊断类别:lint/performance/noBarrelFile

¥Diagnostic Category: lint/performance/noBarrelFile

自从:v1.6.0 来源:

¥Since: v1.6.0 Sources:

禁止使用 barrel 文件。

¥Disallow the use of barrel file.

桶文件是重新导出目录中其他文件的所有导出的文件。此结构导致许多模块不必要地加载,严重影响大型应用的性能。此外,它使代码库复杂化,使得导航和理解项目的依赖图变得困难。此规则忽略 .d.ts 文件和仅类型导出。

¥A barrel file is a file that re-exports all of the exports from other files in a directory. This structure results in the unnecessary loading of many modules, significantly impacting performance in large-scale applications. Additionally, it complicates the codebase, making it difficult to navigate and understand the project’s dependency graph. This rule ignores .d.ts files and type-only exports.

有关更详细的说明,请查看 https://marvinh.dev/blog/speeding-up-javascript-ecosystem-part-7/

¥For a more detailed explanation, check out https://marvinh.dev/blog/speeding-up-javascript-ecosystem-part-7/

¥Examples

¥Invalid

export * from "foo";
export * from "bar";
code-block.ts:1:1 lint/performance/noBarrelFile ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid barrel files, they slow down performance, and cause large module graphs with modules that go unused.

> 1 │ export * from “foo”;
^^^^^^^^^^^^^^^^^^^^
2 │ export * from “bar”;
3 │

Check this thorough explanation to better understand the context.

export { foo } from "foo";
export { bar } from "bar";
code-block.ts:1:1 lint/performance/noBarrelFile ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid barrel files, they slow down performance, and cause large module graphs with modules that go unused.

> 1 │ export { foo } from “foo”;
^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │ export { bar } from “bar”;
3 │

Check this thorough explanation to better understand the context.

export { default as module1 } from "./module1";
code-block.ts:1:1 lint/performance/noBarrelFile ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid barrel files, they slow down performance, and cause large module graphs with modules that go unused.

> 1 │ export { default as module1 } from “./module1”;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

Check this thorough explanation to better understand the context.

¥Valid

export type * from "foo";
export type { foo } from "foo";

¥Related links