# babel-plugin-shaking-import

> Modular import plugin for babel.

Latest version **0.4.0** (published 2017-07-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-shaking-import
pnpm add babel-plugin-shaking-import
yarn add babel-plugin-shaking-import
bun add babel-plugin-shaking-import
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2017-07-14 |
| First published | 2017-07-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | bornkiller |
| Maintainers | bornkiller |
| Keywords | babel, plugin |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-shaking-import
- Repository: https://github.com/bornkiller/babel-plugin-shaking-import
- Homepage: https://github.com/bornkiller/babel-plugin-shaking-import#README
- Issues: https://github.com/bornkiller/babel-plugin-shaking-import/issues
- npm.io page: https://npm.io/package/babel-plugin-shaking-import

## Dependencies (1)

- [babel-types](https://npm.io/package/babel-types.md) ^6.25.0

## 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

- 0.4.0 (latest) — 2017-07-14
- 0.2.0 — 2017-07-08
- 0.1.0 — 2017-07-08

## README

# babel-plugin-shaking-import
![Build Status](https://img.shields.io/travis/bornkiller/babel-plugin-shaking-import/master.svg?style=flat)
[![Coverage Status](https://coveralls.io/repos/github/bornkiller/babel-plugin-shaking-import/badge.svg?branch=master)](https://coveralls.io/github/bornkiller/babel-plugin-shaking-import?branch=master)
![Package Dependency](https://david-dm.org/bornkiller/babel-plugin-shaking-import.svg?style=flat)
![Package DevDependency](https://david-dm.org/bornkiller/babel-plugin-shaking-import/dev-status.svg?style=flat)

Modular import plugin for babel, compatible with antd, antd-mobile, lodash, and so on.

## Changelog
+ `ShakingImportOptions` add property `libraryNameImport` since `v0.4.0`.
+ `ShakingImportOptions` property `style` transform into `libraryStyle`

## Usage
Install:

```shell
# npm
npm install babel-plugin-shaking-import --save-dev
# yarn
yarn add babel-plugin-shaking-import --dev
```

Add babel plugin:

```json
{
  "plugin": [
    ["shaking-import", {
      "libraryName": "antd",
      "libraryDirectory": "lib",
      "libraryStrategy": "camel2dash",  
      "libraryStyle": true    
    }]
  ]
}
```

options can be an object of `ShakingImportOptions`, or an array of `ShakingImportOptions`:

```javascript
/**
 * @typedef {object} ShakingImportOptions
 *
 * @property {string} libraryName - reuqired
 * @property {string} libraryDirectory - optional, defualt lib
 * @property {boolean} libraryNameImport - whether import namespace specifier
 * @property {string} libraryStrategy - optional, default preserve, enum strategy preserve, camel2dash, camel2underline
 * @property {string|boolean} libraryOverride - optional, default false, replace module name in rare condition, like lodash within jest while lodash-es within rollup
 * @property {string|boolean} libraryStyle - optional, default false
 */
```

## Example
```json
[
  {
    "libraryName": "antd",
    "libraryStrategy": "camel2dash",
    "libraryStyle": true
  },
  {
    "libraryName": "lodash",
    "libraryDirectory": "."
  },
  {
    "libraryName": "rxjs",
    "libraryDirectory": ".",
    "libraryNameImport": true
  },
  {
    "libraryName": "react-toolbox",
    "libraryStrategy": "camel2underline"
  }  
]
```

## Showcase

`rxjs shaking`:

```javascript
import { Observable, Subject } from 'rxjs';

// Normal import
import 'rxjs/observable/interval'
import 'rxjs/observable/zip';

const trigger$ = Reflect.construct(Subject, []);
const timer$ = Observable.interval(1000);

Observable.zip(trigger$, timer$).subscribe((value) => {
  console.log(value);
});
```

```javascript
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';

// Normal import
import 'rxjs/observable/interval';
import 'rxjs/observable/zip';

const trigger$ = Reflect.construct(Subject, []);
const timer$ = Observable.interval(1000);

Observable.zip(trigger$, timer$).subscribe(value => {
  console.log(value);
});
```

`antd shaking`:

```javascript
import { Button, DatePicker, message } from 'antd';

message.info('babel-plugin-shaking-import');

ReactDOM.render(<div>
  <DatePicker/>
  <Button>babel-plugin-shaking-import</Button>
</div>);
```

```javascript
import 'antd/lib/button/style/css';
import Button from 'antd/lib/button';
import 'antd/lib/date-picker/style/css';
import DatePicker from 'antd/lib/date-picker';
import 'antd/lib/message/style/css';
import message from 'antd/lib/message';

message.info('babel-plugin-shaking-import');

ReactDOM.render(React.createElement(
  'div',
  null,
  React.createElement(DatePicker, null),
  React.createElement(
    Button,
    null,
    'babel-plugin-shaking-import'
  )
));
```

## License
MIT

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