1 | # babel-plugin-component
|
2 |
|
3 | [![NPM version](https://img.shields.io/npm/v/babel-plugin-component.svg)](https://npmjs.org/package/babel-plugin-component)
|
4 | [![Build Status](https://travis-ci.org/QingWei-Li/babel-plugin-component.svg?branch=master)](https://travis-ci.org/QingWei-Li/babel-plugin-component)
|
5 | [![Coverage Status](https://coveralls.io/repos/github/QingWei-Li/babel-plugin-component/badge.svg?branch=master)](https://coveralls.io/github/QingWei-Li/babel-plugin-component?branch=master)
|
6 |
|
7 | ## Install
|
8 |
|
9 | ```shell
|
10 | npm install babel-plugin-component --save-dev
|
11 | ```
|
12 |
|
13 | ## Example
|
14 |
|
15 | Converts
|
16 |
|
17 | ```javascript
|
18 | import { Button } from 'components'
|
19 | ```
|
20 |
|
21 | to
|
22 |
|
23 | ```javascript
|
24 | var button = require('components/lib/button')
|
25 | require('components/lib/button/style.css')
|
26 | ```
|
27 |
|
28 | ## styleLibraryName Example
|
29 |
|
30 | Converts
|
31 |
|
32 | ```javascript
|
33 | import Components from 'components'
|
34 | import { Button } from 'components'
|
35 | ```
|
36 |
|
37 | to
|
38 |
|
39 | ```javascript
|
40 | require('components/lib/styleLibraryName/index.css')
|
41 | var button = require('components/lib/styleLibraryName/button.css')
|
42 | ```
|
43 |
|
44 | ## Usage
|
45 |
|
46 | Via `.babelrc` or babel-loader.
|
47 |
|
48 | ```javascript
|
49 | {
|
50 | "plugins": [["component", options]]
|
51 | }
|
52 | ```
|
53 |
|
54 | ## Multiple Module
|
55 | ```javascript
|
56 | {
|
57 | "plugins": [xxx, ["component", [
|
58 | {
|
59 | libraryName: 'antd',
|
60 | style: true,
|
61 | },
|
62 | {
|
63 | libraryName: 'test-module',
|
64 | style: true,
|
65 | }
|
66 | ]]]
|
67 | }
|
68 | ```
|
69 |
|
70 | ### Component directory structure
|
71 | ```
|
72 | - lib // 'libDir'
|
73 | - index.js // or custom 'root' relative path
|
74 | - style.css // or custom 'style' relative path
|
75 | - componentA
|
76 | - index.js
|
77 | - style.css
|
78 | - componentB
|
79 | - index.js
|
80 | - style.css
|
81 | ```
|
82 |
|
83 | ### Theme library directory structure
|
84 | ```
|
85 | - lib
|
86 | - theme-default // 'styleLibraryName'
|
87 | - base.css // required
|
88 | - index.css // required
|
89 | - componentA.css
|
90 | - componentB.css
|
91 | - theme-material
|
92 | - ...
|
93 | - componentA
|
94 | - index.js
|
95 | - componentB
|
96 | - index.js
|
97 | ```
|
98 |
|
99 | ### options
|
100 |
|
101 | - `["component"]`: import js modularly
|
102 | - `["component", { "libraryName": "component" }]`: module name
|
103 | - `["component", { "styleLibraryName": "theme_package" }]`: style module name
|
104 | - `["component", { "styleLibraryName": "~independent_theme_package" }]`: Import a independent theme package
|
105 | - `["component", { "style": true }]`: import js and css from 'style.css'
|
106 | - `["component", { "style": cssFilePath }]`: import style css from filePath
|
107 | - `["component", { "libDir": "lib" }]`: lib directory
|
108 | - `["component", { "root": "index" }]`: main file dir
|