Skip to main content

Remove Import

Remove the import module(not include specifier)

info

This rule does not remove cases that contain specifiers.

The reason is that when a specifier is included, the identifiers that use it must also be removed, and we cannot currently cover all the exception cases that occur when removing identifiers.

import "utils";
import "lib";

Options

type Options = {
source: string;
sourceType?: "relative" | "absolute";
};
  • source: remove target source
  • sourceType: remove target source's type. you can choose absolute or relative

Usage

The usage method differs depending on the source type of the import statement to be converted.

absolute

This is a situation where the source of the import module you want to change is an absolute path.

option.ts
const option = {
source: "utils",
};
import "utils";

relative

This is a situation where the source of the import module you want to change is an absolute path.

option.ts
const option = {
source: path.join(process.cwd(), "test/utils.ts"),
sourceType: "relative",
};
import "./test/utils.ts";