Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/activeguild/css-custom-property-extractor

Extract css custom properties as constant values that can be used in JS.
https://github.com/activeguild/css-custom-property-extractor

css css-custom-property extract typescript

Last synced: 27 days ago
JSON representation

Extract css custom properties as constant values that can be used in JS.

Awesome Lists containing this project

README

        

css-custom-property-extractor


npm version
GitHub Actions status

## Intro

- Parse css custom properties and output typescript files.By importing the output typescript files

,custom properties can be used type-safely in various libraries.
- Supports `css` and `sass` and `less`.
- If you are in a vite environment, use the `css-preprocessoroptions` in `vite.config`.

## Usage

1. Install as `devDependencies`

```shell
npm i -D css-custom-property-extractor
```

2. For example.
Parsing [./samples/scss/bootstrap.scss](./samples/scss/bootstrap.scss) outputs the following typescript file.

```shell
npx ccpe -i ./samples/scss/bootstrap.scss
```

```ts
/**
* #0d6efd;
*/
export const bsBlue = "var(--bs-blue)"
/**
* #6610f2;
*/
export const bsIndigo = "var(--bs-indigo)"
/**
* #6f42c1;
*/
export const bsPurple = "var(--bs-purple)"
...
```

3. Import and use the output typescript file.

## Command options

| option | description |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| -o \ | output path. |
| -i,--include | include path (glob pattern). (default \*_/_.?(css \| scss \| sass \| less)) |
| -e,--exclude | exclude path (glob pattern). |
| -v,--vite | Specify the relative path to vite.config.
Read the [css-preprocessoroptions](https://vitejs.dev/config/shared-options.html#css-preprocessoroptions) property from `vite.config`. (default false) |