# postcss-color-variable

> PostCSS plugin color variable

Latest version **0.4.2** (published 2020-04-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install postcss-color-variable
pnpm add postcss-color-variable
yarn add postcss-color-variable
bun add postcss-color-variable
```

Provides the command `postcss-color-variable`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.2 |
| Published | 2020-04-25 |
| First published | 2020-03-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 5 |
| Unpacked size | 21.2 KB |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 5 |
| Author | zengxb94@foxmail.com |
| Maintainers | zengxuebing |
| Keywords | postcss, css, postcss-plugin, color, variable |

## Links

- npm: https://www.npmjs.com/package/postcss-color-variable
- Repository: https://github.com/SimonTart/postcss-color-variable
- Homepage: https://github.com/SimonTart/postcss-color-variable#readme
- Issues: https://github.com/SimonTart/postcss-color-variable/issues
- npm.io page: https://npm.io/package/postcss-color-variable

## Dependencies (5)

- [postcss](https://npm.io/package/postcss.md) ^7.0.18
- [optionator](https://npm.io/package/optionator.md) ^0.9.1
- [cosmiconfig](https://npm.io/package/cosmiconfig.md) ^6.0.0
- [postcss-less](https://npm.io/package/postcss-less.md) ^3.1.4
- [postcss-scss](https://npm.io/package/postcss-scss.md) ^2.0.0

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 0.4.2 (latest) — 2020-04-25
- 0.4.1 — 2020-04-22
- 0.4.0 — 2020-04-22
- 0.3.4 — 2020-04-16
- 0.3.3 — 2020-04-16
- 0.3.2 — 2020-04-16
- 0.3.1 — 2020-04-16
- 0.3.0 — 2020-04-16
- 0.2.4 — 2020-04-16
- 0.2.3 — 2020-04-15
- 0.2.2 — 2020-04-15
- 0.2.1 — 2020-04-15
- 0.2.0 — 2020-04-15
- 0.1.0 — 2020-04-12
- 0.0.18 — 2020-04-11
- … 15 more at https://npm.io/package/postcss-color-variable/versions

## README

# PostCSS Color Variable
[EN](./README) | [ZH](./zh.md)

[PostCSS] plugin color variable. Auto replace color value with corresponding variable name. Now support Less and Sass

Define color variable name file:
```less
@link-color: #0a1;
```

Input:
```less
.foo {
    color: #0a1;
    background: rgb(170, 170, 170);
    border: 1px solid rgba(170, 170, 170, 0.1);
}
```

Output:
```less
.foo {
  color: @link-color;
  background: @link-color;
  border: 1px solid fade(@link-color, 10%);
}
```

## Config
Create file `.colorvarrc.json` in project.
```js
{
  "variableFiles": ["./src/color.less"], // define color variable file path
  "syntax": "less", // syntax，support less, sass. default is less
  "autoImport": "true", // if auto import variable file
  "alias": {
    "@": "./src" // equal webpack alias
  },
  "usingAlias": "@", // when auto import variable file, using alias. for example @import '~@/src/color.less'
  "singleQuote": false, // auto import if using single quote. default is false
}
```

## Use
### CLI
```bash
# install plugin
npm install postcss-color-variable --save-dev
# auto replace by cli
./node_modules/.bin/postcss-color-variable src/index.less

# set syntax by --syntax
./node_modules/.bin/postcss-color-variable src/index.scss --syntax scss
```

### VSCode Extension
https://marketplace.visualstudio.com/items?itemName=zengxb94.color-variable&ssr=false#overview

### Use in WebStorm
#### WebStorm replace Less file
1. Install plugin: `npm install postcss-color-variable --save-dev`
2. Open `Preferences -> File Watchers -> Add`
3. Settings
  - Name: `Color Variable Less`
  - File type: `Less Style Sheet`
  - Program: `$ProjectFileDir$/node_modules/.bin/postcss-color-variable`
  - Arguments: `$FilePathRelativeToProjectRoot$`
  - Output paths to refresh: `$FilePathRelativeToProjectRoot$`
  - Working Directory: `$ProjectFileDir$`
  - set Auto-save edited files to trigger watcher  unchecked
  - set Trigger The watcher on external changes unchecked


### WebStorm replace Sass file
1. Install plugin: `npm install postcss-color-variable --save-dev`
2. Open `Preferences -> File Watchers -> Add`
3. Settings
  - Name: `Color Variable Sass`
  - File type: `Sass Style Sheet`
  - Program: `$ProjectFileDir$/node_modules/.bin/postcss-color-variable`
  - Arguments: `$FilePathRelativeToProjectRoot$`
  - Output paths to refresh: `$FilePathRelativeToProjectRoot$`
  - Working Directory: `$ProjectFileDir$`
  - set Auto-save edited files to trigger watcher  unchecked
  - set Trigger The watcher on external changes unchecked

---
_Source: https://npm.io/package/postcss-color-variable · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
