1. babel-plugin-component
Modular build plugin for babel.
babel-plugin-component
Package: babel-plugin-component
Created by: ElementUI
Last modified: Mon, 13 Jun 2022 04:00:47 GMT
Version: 1.1.1
License: MIT
Downloads: 158,093
Repository: https://github.com/ElementUI/babel-plugin-component

Install

npm install babel-plugin-component
yarn add babel-plugin-component

babel-plugin-component

NPM version
Build Status
Coverage Status

Install

 npm i babel-plugin-component -D

# For babel6
npm i babel-plugin-component@0 -D

Example

Converts

 import { Button } from 'components'

to

 var button = require('components/lib/button')
require('components/lib/button/style.css')

styleLibraryName Example

Converts

 import Components from 'components'
import { Button } from 'components'

to

 require('components/lib/styleLibraryName/index.css')
var button = require('components/lib/styleLibraryName/button.css')

Usage

Via .babelrc or babel-loader.

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

Multiple Module

 {
  "plugins": [xxx,
    ["component", {
      libraryName: "antd",
      style: true,
    }, "antd"],
    ["component", {
      libraryName: "test-module",
      style: true,
    }, "test-module"]
  ]
}

Component directory structure

- lib // 'libDir'
  - index.js // or custom 'root' relative path
  - style.css // or custom 'style' relative path
  - componentA
    - index.js
    - style.css
  - componentB
    - index.js
    - style.css

Theme library directory structure

- lib
  - theme-default // 'styleLibraryName'
    - base.css // required
    - index.css // required
    - componentA.css
    - componentB.css
  - theme-material
    - ...
  - componentA
    - index.js
  - componentB
    - index.js

or

- lib
  - theme-custom // 'styleLibrary.name'
    - base.css // if styleLibrary.base true
    - index.css // required
    - componentA.css // default 
    - componentB.css
  - theme-material
    - componentA
      -index.css  // styleLibrary.path  [module]/index.css
    - componentB
      -index.css
  - componentA
    - index.js
  - componentB
    - index.js

options

  • ["component"]: import js modularly
  • ["component", { "libraryName": "component" }]: module name
  • ["component", { "styleLibraryName": "theme_package" }]: style module name
  • ["component", { "styleLibraryName": "~independent_theme_package" }]: Import a independent theme package
  • ["component", { "styleLibrary": {} }]: Import a independent theme package with more config
    styleLibrary: {
      "name": "xxx", // same with styleLibraryName
      "base": true,  // if theme package has a base.css
      "path": "[module]/index.css",  // the style path. e.g. module Alert =>  alert/index.css
      "mixin": true  // if theme-package not found css file, then use [libraryName]'s css file
    }
    
  • ["component", { "style": true }]: import js and css from 'style.css'
  • ["component", { "style": cssFilePath }]: import style css from filePath
  • ["component", { "libDir": "lib" }]: lib directory
  • ["component", { "root": "index" }]: main file dir
  • ["component", { "camel2Dash": false }]: whether parse name to dash mode or not, default true

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code