# @m860/cerberus-babel-plugin-transform

> cerberus转换工具

Latest version **1.1.4** (published 2020-07-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @m860/cerberus-babel-plugin-transform
pnpm add @m860/cerberus-babel-plugin-transform
yarn add @m860/cerberus-babel-plugin-transform
bun add @m860/cerberus-babel-plugin-transform
```

## 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.4 |
| Published | 2020-07-29 |
| First published | 2019-11-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | m860 |
| Maintainers | m860 |

## Links

- npm: https://www.npmjs.com/package/@m860/cerberus-babel-plugin-transform
- Repository: https://github.com/m860/cerberus-babel-plugin-transform
- Homepage: https://github.com/m860/cerberus-babel-plugin-transform#readme
- Issues: https://github.com/m860/cerberus-babel-plugin-transform/issues
- npm.io page: https://npm.io/package/@m860/cerberus-babel-plugin-transform

## Recent versions

- 1.1.4 (latest) — 2020-07-29
- 1.1.3 — 2020-07-29
- 1.1.2 — 2020-07-28
- 1.1.1 — 2019-11-29
- 1.1.0 — 2019-11-29
- 1.0.0 — 2019-11-26

## README

# cerberus-babel-plugin-transform

cerberus转换工具

## Install

`npm i -D @m860/cerberus-babel-plugin-transform`

## Usage

> NOTE:默认情况下`react`,`react-native`会被替换

```json
{
  "plugins": ["@cerberus/transform"]
}
```

如果需要替换自己的模块可以设置`modules`参数

```json
{
  "plugins": [["@cerberus/transform",{"modules": ["dateformat"]}]]
}
```

> NOTE: `modules`中设置的module名字和npm保持一致，在`Cerberus`库中导出的名字也必须一致。


## Option

```flow js
type Option={
    /**
     * 不需要被打包的公共模块
     */
    modules?:Array<string>,
    /**
     * 需要处理的资源文件的正则表达式，默认：/\.(gif|png|jpeg|jpg|svg)$/i 
     */
    resourceTest?:?RegExp
};
```

## Examples

```
// input
import * as React from "react"
import React2 from "react"
import {memo,useState} from "react"
import {useRef as ur} from "react"
import {Text} from "react-native"
import df from "dateformat"
import {get as getPath} from "object-path"

// output
const React = $REACT$;
const React2 = $REACT$;
const memo = $REACT$.memo;
const useState = $REACT$.useState;
const ur = $REACT$.useRef;
const Text = $REACTNATIVE$.Text;
const df = $MODULES$["dateformat"];
const getPath = $MODULES$["object-path"].get;
```

<!--

[ASTExplorer](https://astexplorer.net/)在线调试工具

[Babel插件开发手册](https://github.com/jamiebuilds/babel-handbook/blob/master/translations/zh-Hans/plugin-handbook.md)

[babel-types API](https://babeljs.io/docs/en/babel-types)

## TODO

- [ ] 处理`require("*.png")`,如果是资源文件需要进行重定向到`http`
    ```js 
    // input
    <Image source={require("logo.png")}/>
    // output
    <Image source={{uri:`${$MODULES$.BASE_URL}/${require("logo.png")}`}}/>
    ```
- [ ] `modules`支持别名设置
    ```
    // 例如
    {
        modules:[
            {
                name:"dateformat",
                exportName:"df"
            }
        ]
    }
    ```
-->

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