# @zhangliu/babel-plugin-class-to-css

> plugin can generate css by class name.

Latest version **1.2.24** (published 2019-10-18) · 0 weekly downloads

## Install

```sh
npm install @zhangliu/babel-plugin-class-to-css
pnpm add @zhangliu/babel-plugin-class-to-css
yarn add @zhangliu/babel-plugin-class-to-css
bun add @zhangliu/babel-plugin-class-to-css
```

## 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.2.24 |
| Published | 2019-10-18 |
| First published | 2019-06-15 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 31.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | zhangliu |
| Maintainers | zhangliu |
| Keywords | babel-plugin |

## Links

- npm: https://www.npmjs.com/package/@zhangliu/babel-plugin-class-to-css
- Repository: https://github.com/zhangliu/babel-plugin-class-to-css
- Homepage: https://github.com/zhangliu/babel-plugin-class-to-css#readme
- Issues: https://github.com/zhangliu/babel-plugin-class-to-css/issues
- npm.io page: https://npm.io/package/@zhangliu/babel-plugin-class-to-css

## Dependencies (2)

- [react](https://npm.io/package/react.md) ^16.8.6
- [babel-preset-react](https://npm.io/package/babel-preset-react.md) ^6.24.1

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.2.24 (latest) — 2019-10-18
- 1.1.24 — 2019-09-21
- 1.1.23 — 2019-09-19
- 1.1.22 — 2019-09-19
- 1.1.21 — 2019-09-11
- 1.1.20 — 2019-09-09
- 1.1.19 — 2019-08-29
- 1.1.18 — 2019-08-20
- 1.1.17 — 2019-08-20
- 1.1.16 — 2019-08-20
- 1.1.15 — 2019-08-20
- 1.1.14 — 2019-08-20
- 1.1.12 — 2019-08-20
- 1.1.11 — 2019-08-15
- 1.1.10 — 2019-08-13
- … 34 more at https://npm.io/package/@zhangliu/babel-plugin-class-to-css/versions

## README

# babel-plugin-class-to-css

这个插件可以根据你的标签className简写名称，自动的生成相应的css样式！

## Example

**转换前代码**

```js
import React from 'react'
export default () => (
  <div className="fs12 mt10 pa t0">
    <span className="p20">hello world!</span>
  </div>
)
```

**转换后代码**

```js
import React from 'react'
export default () => (
  <div className="fs12 mt10 pa t0">
    <span className="p20">hello world!</span>
    <style dangerouslySetInnerHTML={{_html: `
      .fs12{font-size: 12px}
      .mt10{margin-top: 10px}
      .pa{position: absolute}
      .t0{top: 0px}
      .p20{padding: 20px}
    `}}/>
  </div>
)
```

可以看到，只用本插件，可以省去不必要的css样式的编写工作。

## 转换规则（使用了正则转换）
|  className简写  |     转换后       |                  例子                  |
|------------------------|:------------------:|----------------------------------:|
| m(\d+) |  margin: $1px | 例如：m10 转换为 margin: 10px |
| mt(\d+) |  margin-top: $1px | 例如：mt10 转换为 margin-top: 10px |
| fs(\d+) |  font-size: $1px | 例如：fs10 转换为 font-size: 10px |
| 未完待添加... | 未完待添加... | 未完待添加... |

## Installation

```sh
$ npm install babel-plugin-class-to-css
```

## Usage

### Via `.babelrc` (Recommended)

**.babelrc**

```json
{
  "plugins": ["class-to-css"]
}
```

### Via CLI

```sh
$ babel --plugins class-to-css script.js
```

### Via Node API

```javascript
require("babel-core").transform("code", {
  plugins: ["class-to-css"]
});
```

---
_Source: https://npm.io/package/@zhangliu/babel-plugin-class-to-css · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
