Skip to content

VKCOM/swc-plugin-transform-remove-imports

Folders and files

NameName
Last commit message
Last commit date

Latest commit

1bb47c2 · Oct 23, 2023
May 15, 2023
Oct 3, 2023
Feb 2, 2023
Feb 8, 2023
Oct 23, 2023
Oct 16, 2023
Feb 2, 2023
Feb 2, 2023
Oct 16, 2023
Jul 31, 2023
Feb 8, 2023

Repository files navigation

swc-plugin-transform-remove-imports

A Rust versions of babel-plugin-transform-remove-imports.

Modular import plugin for swc. Also works for cjs to delete imported CSS to avoid compilation errors.

Installation

npm:

npm i -D swc-plugin-transform-remove-imports

yarn:

yarn add -D swc-plugin-transform-remove-imports

Usage

Via .swcrc

{
  "jsc": {
    "experimental": {
      "plugins": [
        [
          "swc-plugin-transform-remove-imports",
          {
            "test": "\\.(less|css)$"
          }
        ]
      ]
    }
  }
}

Support import

// Input Code
import "./index.less";
import "./index.main.less";
import { Button } from "uiw";
import { Select } from "@uiw/core";

// Output   ↓ ↓ ↓ ↓ ↓ ↓
import { Button } from "uiw";
import { Select } from "@uiw/core";

Output Result

- import './index.less';
- import './index.main.less';
import { Button } from 'uiw';
import { Select } from '@uiw/core';

Support require

Options

test

Type: Regex | Regex[]

A regular expression to match the imports that will be removed.

remove

Optional. Possible values: 'effects'

Removing only side effects imports.

// Input Code
import "foo";
import Foo from "foo";

// Output Code  ↓ ↓ ↓ ↓ ↓ ↓
import Foo from "foo";

License

MIT