# babel-plugin-less-color-to-js

> [中文](./README.zh.md)

Latest version **1.0.8** (published 2023-07-31) · ISC license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-less-color-to-js
pnpm add babel-plugin-less-color-to-js
yarn add babel-plugin-less-color-to-js
bun add babel-plugin-less-color-to-js
```

## 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.0.8 |
| Published | 2023-07-31 |
| First published | 2023-07-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | zhengen |
| Maintainers | zhengen |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-less-color-to-js
- Repository: https://github.com/enzheng128/babel-plugin-less-color-to-js
- Homepage: https://github.com/enzheng128/babel-plugin-less-color-to-js#readme
- Issues: https://github.com/enzheng128/babel-plugin-less-color-to-js/issues
- npm.io page: https://npm.io/package/babel-plugin-less-color-to-js

## Recent versions

- 1.0.8 (latest) — 2023-07-31
- 1.0.7 — 2023-07-31
- 1.0.6 — 2023-07-28
- 1.0.5 — 2023-07-28
- 1.0.4 — 2023-07-28
- 1.0.3 — 2023-07-28
- 1.0.2 — 2023-07-28
- 1.0.1 — 2023-07-28
- 1.0.0 — 2023-07-28

## README

# babel-plugin-less-color-to-js
[中文](./README.zh.md)

## Introduction

`babel-plugin-less-color-to-js` is a Babel plugin designed to address the issue of using LESS color variables in JavaScript. The plugin will automatically replace corresponding JavaScript string literals with color variables defined in a global LESS file. This means that you can directly use the names of LESS color variables in your JavaScript files without worrying about color values.

## Installation

To install via npm:

```bash
npm install --save-dev babel-plugin-less-color-to-js
```

## Usage

First, you need to create an instance of `BabelLessColorToJs`, providing the path of your global LESS file:

```javascript
const BabelLessColorToJs = require('babel-plugin-less-color-to-js');

const babelLessColorToJs = new BabelLessColorToJs({
  fileName: 'path/to/your/less/file.less',
});
```

Then, add this instance to the plugins array in your Babel configuration:

```javascript
module.exports = {
  // ...
  plugins: [
    // ...
    babelLessColorToJs,
    // ...
  ],
};
```

Now, the color variables defined in your global LESS file can be directly used in JavaScript. For example, if you have a color variable `@primary-color: #1DA57A;`, you can use it in your JavaScript file like this:

```javascript
const color = '@primary-color';  // This will be replaced with '#1DA57A'
```

Be aware that this plugin affects all string literals, not just those used in style properties. Therefore, you need to ensure that strings in your code that share names with color variables are not inadvertently replaced.

## Notes

- If the LESS file are updated during the build process, you may need to restart the build to ensure the accuracy of the color values.

- This plugin can only handle color variables defined in the LESS file. If your color values are defined in JavaScript or in CSS, SCSS, Stylus, or other style files, this plugin may not be able to handle them correctly.

## Contributing

Contributions to this project are welcome. If you have any questions or suggestions, you can submit them through issues or pull requests.

---
_Source: https://npm.io/package/babel-plugin-less-color-to-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
