@wii/babel-plugin-tea-component
v2.0.0
Published
Tea Component modular import plugin for babel.
Downloads
1
Readme
babel-plugin-tea-component
Fork from
babel-plugin-tea-component
Usage
1. 安装
npm install @wii/babel-plugin-tea-component --save-dev
2. 配置
设置 .babelrc
或 babel-loader 的配置.
{
"plugins": ["@wii/babel-plugin-tea-component", ...],
// 携带配置
"plugins": [["@wii/babel-plugin-tea-component", options], ...],
}
Example
// .babelrc
{
"plugins": [[
"@wii/babel-plugin-tea-component",
{},
"tea component"
], [
"@wii/babel-plugin-tea-component",
{
"libraryName": "@wii/tea-chart",
"actualLib": "@wii/tea-chart/lib"
},
"tea chart"
]]
}
import { Button, SlideTransition } from '@wii/tea-component';
import { BasicLine } from '@wii/tea-chart';
ReactDOM.render(
<SlideTransition>
<Button>xxxx</Button>
<BasicLine />
</SlideTransition>
);
// ===== 上方代码将会转换为 ↓ =====
import { Button } from '@wii/tea-component/lib/button';
import { SlideTransition } from '@wii/tea-component/lib/transition';
import { BasicLine } from '@wii/tea-chart/lib/basicline';
ReactDOM.render(
<SlideTransition>
<Button>xxxx</Button>
<BasicLine />
</SlideTransition>
);
Options
libraryName
: string
默认 "@wii/tea-component"
指定插件在转换阶段需要检测的 module name
libraryDirectory
: string
默认 "lib"
指定插件在转换后生成的新 import path 中携带的后缀
actualLib
: string
默认 @wii/tea-component/lib
指定需要从哪个路径读取 tea-component/lib 结构,将会使用 path.dirname(require.resolve(actualLib))
处理
actualLibPath
: string
默认 undefined
指定需要从哪个路径读取 tea-component/lib 结构,不会进行 require.resolve
处理,若指定则忽略 actualLib