npm package: @moneko/transform-imports
Description: A wasm swc transform imports plugin
Author: moneko
Latest version: 1.4.0

# @moneko/transform-imports

A wasm plugin for swc, inspired from [babel-plugin-transform-imports](https://www.npmjs.com/package/babel-plugin-transform-imports).

## Installation

```bash
npm install --save-dev @moneko/transform-imports
# or
yarn add -D @moneko/transform-imports
```

## Usage

It follows resolving rule of node.js, can be use in `.swcrc`，`webpack.config.js` or `next.config.js` and so on. For Example:

```json
{
  "jsc": {
    "experimental": {
      "plugins": [
        [
          "@moneko/transform-imports",
          {
            "antd": {
              "transform": "antd/lib/${member}",
              "skipDefaultConversion": false,
              "preventFullImport": true,
              "style": "antd/lib/${member}/style",
              "memberTransformers": ["dashed_case"]
            },
            "lodash": {
              "transform": "lodash/${member}",
              "preventFullImport": true
            }
          }
        ]
      ]
    }
  }
}
```

Can convert the following lines:

```js
import { Button as MyButton, BackTop } from "antd";
import { merge } from "lodash";
```

To:

```js
import MyButton from "antd/lib/button";
import "antd/lib/button/style";
import BackTop from "antd/lib/back-top";
import "antd/lib/back-top/style";
import merge from "lodash/merge";
```

## Options

| Name                    | Type                       | Required | Default     | Description                                                                                                                                     |
|-------------------------|----------------------------|----------|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| `transform`             | `string`                   | yes      | `undefined` | The library name to use instead of the one specified in the import statement. ${member} will be replaced with the member, aka Grid/Row/Col/etc. |
| `preventFullImport`     | `boolean`                  | no       | `true`      | Whether or not to throw when an import is encountered which would cause the entire module to be imported.                                       |
| `skipDefaultConversion` | `boolean`                  | no       | `false`     | When set to true, will preserve `import { X }` syntax instead of converting to `import X`.                                                      |
| `style`                 | `string`                   | no       | `false`     | The style path of the member, ${member} will be replaced with the member, aka Grid/Row/Col/etc.                                                 |
| `memberTransformers`    | `Array<MemberTransformer>` | no       | []          | Member transformers                                                                                                                             |

### 1. `type MemberTransformer`

```typescript
type MemberTransformer =
  | "camel_case"
  | "kebab_case"
  | "pascal_case"
  | "snake_case"
  | "upper_case"
  | "upper_first"
  | "lower_case"
  | "lower_first"
  | "dashed_case";
```