# postcss-prune-var

> PostCSS plugin to remove unused variables

Latest version **1.1.2** (published 2024-03-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install postcss-prune-var
pnpm add postcss-prune-var
yarn add postcss-prune-var
bun add postcss-prune-var
```

## 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.1.2 |
| Published | 2024-03-03 |
| First published | 2022-06-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 7.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 39 |
| Author | tomasklaen |
| Maintainers | tomasklaen |
| Keywords | postcss, postcss-plugin, unused, prune, remove, var, variable |

## Links

- npm: https://www.npmjs.com/package/postcss-prune-var
- Repository: https://github.com/tomasklaen/postcss-prune-var
- Homepage: https://github.com/tomasklaen/postcss-prune-var#readme
- Issues: https://github.com/tomasklaen/postcss-prune-var/issues
- npm.io page: https://npm.io/package/postcss-prune-var

## Dependencies (1)

- [minimatch](https://npm.io/package/minimatch.md) ^9.0.3

## Recent versions

- 1.1.2 (latest) — 2024-03-03
- 1.1.1 — 2023-05-14
- 1.1.0 — 2023-05-14
- 1.0.5 — 2023-04-29
- 1.0.4 — 2022-06-10
- 1.0.3 — 2022-06-09
- 1.0.2 — 2022-06-09
- 1.0.1 — 2022-06-09
- 1.0.0 — 2022-06-09

## README

# postcss-prune-var

PostCSS plugin to remove all unused variables in a CSS file.

A `--variable` is considered unused if it, or any other variables consuming it are not accessed by a single `var()` statement in the whole CSS file.

This is unsafe if there is a possibility of a second CSS file accessing variables from the first one.

#### How does it work, and how is it different from postcss-unused-var?

-   `postcss-unused-var` is outdated, deprecated, and didn't work right.
-   Treats all variables as global, because they are.
-   Removes variables from everywhere, including `:root`.
-   Checks and prevents removal of variables only used by other variables that are accessed with `var()` by following variable dependency graph.
-   At the same time, if a variable is only used by other unused variables, it will also be removed.
-   Way faster.

## Install

```
npm install postcss-prune-var --save-dev
```

## Usage

```js
const pruneVar = require('postcss-prune-var');

const yourConfig = {
	plugins: [pruneVar()],
};
```

## Options

### skip

Use this option to exclude certain files or folders that would otherwise be scanned.

```js
const pruneVar = require('postcss-prune-var');

const yourConfig = {
	plugins: [pruneVar({skip: ['node_modules/**']})],
};
```
## Example

Input:

```css
:root {
	--root-unused: red;
	--root-unused-proxy: var(--root-unused);
	--root-used: blue;
}

.foo {
	--unused: red;
	--unused-proxy: var(--unused);
	--proxied: pink;
	--proxy: var(--proxied);
	--used: green;
	color: var(--root-used);
	background: linear-gradient(to bottom, var(--used), var(--proxy));
}
```

Output

```css
:root {
	--root-used: blue;
}

.foo {
	--proxied: pink;
	--proxy: var(--proxied);
	--used: green;
	color: var(--root-used);
	background: linear-gradient(to bottom, var(--used), var(--proxy));
}
```

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