Skip to content

noNamespaceImport

诊断类别:lint/style/noNamespaceImport

¥Diagnostic Category: lint/style/noNamespaceImport

自从:v1.6.0 来源:

¥Since: v1.6.0 Sources:

禁止使用命名空间导入。

¥Disallow the use of namespace imports.

命名空间导入可能会影响 tree shake 的效率,tree shake 是从包中删除未使用代码的过程。树摇动的有效性在很大程度上取决于打包器(例如 Webpack、Rollup)及其配置。现代打包器通常能够有效地处理命名空间导入,但建议使用命名导入以实现最佳的树摇动并最小化打包大小。

¥Namespace imports might impact the efficiency of tree shaking, a process that removes unused code from bundles. The effectiveness of tree shaking largely depends on the bundler (e.g., Webpack, Rollup) and its configuration. Modern bundlers are generally capable of handling namespace imports effectively, but using named imports is recommended for optimal tree shaking and minimizing bundle size.

¥Examples

¥Invalid

import * as foo from "foo";
code-block.js:1:8 lint/style/noNamespaceImport ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid namespace imports, it can prevent efficient tree shaking and increase bundle size.

> 1 │ import * as foo from “foo”;
^^^^^^^^^^^^^^^^^^^
2 │

Use named imports instead.

¥Valid

import { foo } from "foo"
import type { bar } from "bar"
import type * as baz from "baz"

¥Related links