1.1.0 • Published 7 years ago

babel-plugin-import2 v1.1.0

Weekly downloads
2
License
MIT
Repository
-
Last release
7 years ago

babel-plugin-import2

在原有 babel-plugin-import 基础上,增加支持路径转发

例如

转换

import { Button } from 'yd';

ReactDOM.render(<div>
  <Button>xxxx</Button>
</div>);

var _button = require('xxx/yd/lib/button');

ReactDOM.render(<div>
  <_button>xxxx</_button>
</div>);

Usage

npm install babel-plugin-import2 --save-dev

通过配置 .babelrc or babel-loader.

{
  "plugins": [["import", options]]
}

options

options 可以是个对象

{
  "libraryName": "yd",
  "style": true,   // or 'css'
  "proxyTarget": "xxx/yd"
}

options 可以是个数组。

[
  {
    "libraryName": "ya",
    "style": true,   // or 'css'
    "proxyTarget": "xxx/yd"
  },
  {
    "libraryName": "yb",
    "camel2DashComponentName": false,
    "proxyTarget": "xxx/yd"
  },
]

options 参数说明

  • camel2DashComponentName 是否将驼峰命名转为下划线
  • libraryName 进行转换的目标包名
  • proxyTarget 将目标包名映射到的新目录,基于process.cwd()