# babel-plugin-transform-imports-api

> Convert import default package API to modular reference to reduce package size and transforms member style imports.

Latest version **1.0.0** (published 2021-01-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-transform-imports-api
pnpm add babel-plugin-transform-imports-api
yarn add babel-plugin-transform-imports-api
bun add babel-plugin-transform-imports-api
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-01-12 |
| First published | 2021-01-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 43 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | shinken008@gmail.com |
| Maintainers | shinken008 |
| Keywords | babel plugin, typescript, import, api |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-transform-imports-api
- npm.io page: https://npm.io/package/babel-plugin-transform-imports-api

## Dependencies (1)

- [is-invalid-path](https://npm.io/package/is-invalid-path.md) ^1.0.2

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2021-01-12
- 0.2.1 — 2021-01-09
- 0.1.0 — 2021-01-08

## README

## babel-plugin-transform-imports-api

[![NPM version](https://img.shields.io/npm/v/babel-plugin-transform-imports-api.svg)](https://www.npmjs.org/package/babel-plugin-transform-imports-api)
[![Build Status](https://travis-ci.org/shinken008/babel-plugin-transform-imports-api.svg?branch=main)](https://travis-ci.org/shinken008/babel-plugin-transform-imports-api)
[![Coverage Status](https://coveralls.io/repos/github/shinken008/babel-plugin-transform-imports-api/badge.svg?branch=main)](https://coveralls.io/github/shinken008/babel-plugin-transform-imports-api?branch=main)

Convert import default package API to modular reference to reduce package size and transforms member style imports. Inspired by [babel-plugin-transform-taroapi](https://www.npmjs.com/package/babel-plugin-transform-taroapi) and [babel-transform-imports](https://bitbucket.org/amctheatres/babel-transform-imports).

## example
```js
import Taro from '@tarojs/taro-h5'
Taro.request(...)
```
This code will become:
```js
import { request } from '@tarojs/taro-h5'
request(...)
```
and when the configure is:
```
// .babelrc
{
  packagesApis: new Map([
    ['@tarojs/taro-h5', new Set(['request'])],
  ]),
  usePackgesImport: true,
  packagesImport: {
    '@tarojs/taro-h5': {
      transform: (importName, matches) => `@tarojs/taro-h5/lib/${importName.toUpperCase()}`,
      preventFullImport: true,
    },
  }
}
```
this code will become:
```js
import request from '@tarojs/taro-h5/lib/request';
request(...)
```

## Usage
### Step 1: Install
```sh
yarn add --dev babel-plugin-transform-imports-api
```
or
```sh
npm install --save-dev babel-plugin-transform-imports-api
```
### Step 1: Configure .babelrc
```js
{
  plugins: [
    [require(plugin), {
      packagesApis: new Map([
        ['packageName1', new Set(['api'])],
        ['packageName2', new Set(['api'])],
      ]),
      usePackgesImport: false, // Whether to use packagesImport
      packagesImport: {
        'packageName1': {
          transform: (importName, matches) => `packageName1/lib/${importName.toUpperCase()}`,
          preventFullImport: true,
        },
      }
    }]
  ]
}
```

---
_Source: https://npm.io/package/babel-plugin-transform-imports-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
