# @gutenye/babel-plugin-transform-imports

> Transforms member style imports (import {x} from 'y') into default style imports (import x from 'y/lib/x')

Latest version **1.1.12** (published 2017-03-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install @gutenye/babel-plugin-transform-imports
pnpm add @gutenye/babel-plugin-transform-imports
yarn add @gutenye/babel-plugin-transform-imports
bun add @gutenye/babel-plugin-transform-imports
```

## 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.1.12 |
| Published | 2017-03-09 |
| First published | 2017-03-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | AMC Theatres |
| Maintainers | gutenye |
| Keywords | babel, transform, import, react-bootstrap, lodash |

## Links

- npm: https://www.npmjs.com/package/@gutenye/babel-plugin-transform-imports
- Repository: https://bitbucket.org/amctheatres/babel-transform-imports
- npm.io page: https://npm.io/package/@gutenye/babel-plugin-transform-imports

## Dependencies (2)

- [babel-types](https://npm.io/package/babel-types.md) ^6.6.0
- [lodash.kebabcase](https://npm.io/package/lodash.kebabcase.md) ^4.0.1

## 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.1.12 (latest) — 2017-03-09
- 1.1.11 — 2017-03-09

## README

# babel-plugin-transform-imports

forked from https://bitbucket.org/amctheatres/babel-transform-imports

- add replace option

```
{
  'react-icons': {
    transform: 'react-icons/lib/${member}',
    replace: ['^(..)-', '$1/'],
    kebabCase: true,
  }
}

import { MdCheck, FaCheck } from 'react-icons'
->
import MdCheck from 'react-icons/lib/md/check'
import FaCheck from 'react-icons/lib/fa/check'
```

Install

```
npm install @gutenye/babel-transform-imports
```

Transforms member style imports:

```javascript
    import { Row, Grid as MyGrid } from 'react-bootstrap';
    import { merge } from 'lodash';
```

...into default style imports:

```javascript
    import Row from 'react-bootstrap/lib/Row';
    import MyGrid from 'react-bootstrap/lib/Grid';
    import merge from 'lodash/merge';
```

## That's stupid, why would you do that?

When Babel encounters a member style import such as:

```javascript
    import { Grid, Row, Col } from 'react-bootstrap';
```

it will generate something similarish to:

```javascript
    var reactBootstrap = require('react-bootstrap');
    var Grid = reactBootstrap.Grid;
    var Row = reactBootstrap.Row;
    var Col = reactBootstrap.Col;
```

Some libraries, such as react-bootstrap and lodash, are rather large and
pulling in the entire module just to use a few pieces would cause unnecessary
bloat to your client optimized (webpack etc.) bundle.  The only way around
this is to use default style imports:

```javascript
    import Grid from 'react-bootstrap/lib/Grid';
    import Row from 'react-bootstrap/lib/Row';
    import Col from 'react-bootstrap/lib/Col';
```

But, the more pieces we need, the more this sucks.  This plugin will allow you
to pull in just the pieces you need, without a separate import for each item.
Additionally, it can be configured to throw when somebody accidentally writes
an import which would cause the entire module to resolve, such as:

```javascript
    import Bootstrap, { Grid } from 'react-bootstrap';
    // -- or --
    import * as Bootstrap from 'react-bootstrap';
```

## Installation

```
npm install --save-dev babel-plugin-transform-imports
```

## Usage

*In .babelrc:*

```json
    {
        "plugins": [
            ["transform-imports", {
                "react-bootstrap": {
                    "transform": "react-bootstrap/lib/${member}",
                    "preventFullImport": true
                },
                "lodash": {
                    "transform": "lodash/${member}",
                    "preventFullImport": true
                }
            }]
        ]
    }
```

That's it!

*Note: this plugin is not restricted to the react-bootstrap and lodash
libraries.  You may use it with any library, where the options keys
(**react-bootstrap** and **lodash** above) are the actual names of the
libraries.*

## 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 | `false` | Whether or not to throw when an import is encountered which would cause the entire module to be imported. |
| `kebabCase` | `boolean` | no | `false` | When set to true, runs ${member} through _.kebabCase. |

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