# postcss-extend-rule

> Use the @extend at-rule and functional selectors in CSS

Latest version **4.0.0** (published 2022-02-10) · CC0-1.0 license · 0 weekly downloads

## Install

```sh
npm install postcss-extend-rule
pnpm add postcss-extend-rule
yarn add postcss-extend-rule
bun add postcss-extend-rule
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2022-02-10 |
| First published | 2017-09-19 |
| Weekly downloads | 0 |
| License | CC0-1.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | ^12 \|\| ^14 \|\| >=16 |
| Dependencies | 1 |
| Unpacked size | 24.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 54 |
| Author | Jonathan Neal |
| Maintainers | alaguna, jonathantneal |
| Keywords | postcss, css, postcss-plugin, extend, matched, matches, match, selectors, subclassing, subclasses, subclass, styling, styles, style, placeholder, placehold, selectors, selector, chaining |

## Links

- npm: https://www.npmjs.com/package/postcss-extend-rule
- Repository: https://github.com/csstools/postcss-extend-rule
- Homepage: https://github.com/csstools/postcss-extend-rule#readme
- Issues: https://github.com/csstools/postcss-extend-rule/issues
- npm.io page: https://npm.io/package/postcss-extend-rule

## Dependencies (1)

- [postcss-nesting](https://npm.io/package/postcss-nesting.md) ^10.1.2

## 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

- 4.0.0 (latest) — 2022-02-10
- 3.0.0 — 2019-07-29
- 2.0.0 — 2018-05-31
- 1.1.0 — 2017-09-19

## README

# PostCSS Extend Rule [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS" width="90" height="90" align="right">][postcss]

[![NPM Version][npm-img]][npm-url]
[![test](https://github.com/csstools/postcss-extend-rule/actions/workflows/test.yml/badge.svg)](https://github.com/csstools/postcss-extend-rule/actions/workflows/test.yml)
[<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]

[PostCSS Extend Rule] lets you use the `@extend` at-rule and
[Functional Selectors] in CSS, following the speculative
[CSS Extend Rules Specification].

```pcss
%thick-border {
  border: thick dotted red;
}

.serious-modal {
  font-style: normal;
  font-weight: bold;

  @media (max-width: 240px) {
    @extend .modal:hover;
  }
}

.modal {
  @extend %thick-border;

  color: red;
}

.modal:hover:not(:focus) {
  outline: none;
}

/* becomes */

.serious-modal {
  font-style: normal;
  font-weight: bold;
}

@media (max-width: 240px) {
  .serious-modal:not(:focus) {
    outline: none;
  }
}

.modal {
  border: thick dotted red;
  color: red;
}

.modal:hover:not(:focus) {
  outline: none;
}
```

## Usage

Add [PostCSS Extend Rule] to your project:

```bash
npm install postcss postcss-extend-rule --save-dev
```

Use **PostCSS Extend Rule** to process your CSS:

```js
const postcssExtendRule = require('postcss-extend-rule');

postcssExtendRule.process(YOUR_CSS /*, processOptions, pluginOptions */);
```

Or use it as a [PostCSS] plugin:

```js
const postcss = require('postcss');
const postcssExtendRule = require('postcss-extend-rule');

postcss([
  postcssExtendRule(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);
```

**PostCSS Extend Rule** runs in all Node environments, with special instructions for:

| [Node](INSTALL.md#node) | [PostCSS CLI](INSTALL.md#postcss-cli) | [Webpack](INSTALL.md#webpack) | [Create React App](INSTALL.md#create-react-app) | [Gulp](INSTALL.md#gulp) | [Grunt](INSTALL.md#grunt) |
| --- | --- | --- | --- | --- | --- |

## Options

### name

The `name` option determines the at-rule name being used to extend selectors.
By default, this name is `extend`, meaning `@extend` rules are parsed.

```js
postcssExtend({ name: 'postcss-extend' })
```

If the `name` option were changed to, say, `postcss-extend`, then only
`@postcss-extend` at-rules would be parsed.

```pcss
main {
  @postcss-extend .some-rule;
}
```

### onFunctionalSelector

The `onFunctionalSelector` option determines how functional selectors should be
handled. Its options are:

- `remove` (default) removes any functional selector
- `ignore` ignores any functional selector and moves on
- `warn` warns the user whenever it encounters a functional selector
- `throw` throws an error if ever it encounters a functional selector

```js
postcssExtend({ onFunctionalSelector: 'remove' /* default */ })
```

```pcss
%this-will-be-removed {}
```

### onRecursiveExtend

The `onRecursiveExtend` option determines how recursive extend at-rules should
be handled. Its options are:

- `remove` (default) removes any recursive extend at-rules
- `ignore` ignores any recursive extend at-rules and moves on
- `warn` warns the user whenever it encounters a recursive extend at-rules
- `throw` throws an error if ever it encounters a recursive extend at-rules

```js
postcssExtend({ onRecursiveExtend: 'remove' /* default */ })
```

```pcss
.this-will-not-extend-itself {
  @extend .this-will-not-extend-itself;
}
```

### onUnusedExtend

The `onUnusedExtend` option determines how an unused extend at-rule should be
handled. Its options are:

- `remove` (default) removes any unused extend at-rule
- `ignore` ignores any unused extend at-rule and moves on
- `warn` warns the user whenever it encounters an unused extend at-rule
- `throw` throws an error if ever it encounters an unused extend at-rule

```js
postcssExtend({ onUnusedExtend: 'remove' /* default */ })
```

```pcss
main {
  @extend .this-selector-does-not-exist-and-will-be-removed;
}
```

[git-img]: https://img.shields.io/badge/support-chat-blue.svg
[discord]: https://discord.gg/bUadyRwkJS
[npm-img]: https://img.shields.io/npm/v/postcss-extend-rule.svg
[npm-url]: https://www.npmjs.com/package/postcss-extend-rule

[CSS Extend Rules Specification]: https://jonathantneal.github.io/specs/css-extend-rule/
[Functional Selectors]: https://jonathantneal.github.io/specs/css-extend-rule/#functional-selector
[PostCSS]: https://github.com/postcss/postcss
[PostCSS Extend Rule]: https://github.com/csstools/postcss-extend-rule

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