# postcss-simple-extend

> Simple extends for PostCSS

Latest version **1.0.0** (published 2015-08-27) · MIT license · 381 weekly downloads

## Install

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

## 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.0 |
| Published | 2015-08-27 |
| First published | 2015-01-24 |
| Weekly downloads | 381 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 34 |
| Author | David Clark |
| Maintainers | davidtheclark |
| Keywords | css, postcss, postcss-plugin, mixin, clone, extend |

## Links

- npm: https://www.npmjs.com/package/postcss-simple-extend
- Repository: https://github.com/davidtheclark/postcss-simple-extend
- Issues: https://github.com/davidtheclark/postcss-simple-extend/issues
- npm.io page: https://npm.io/package/postcss-simple-extend

## Dependencies (1)

- [postcss](https://npm.io/package/postcss.md) ^5.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

- 1.0.0 (latest) — 2015-08-27
- 0.3.2 — 2015-07-11
- 0.3.1 — 2015-04-12
- 0.3.0 — 2015-04-08
- 0.2.0 — 2015-03-15
- 0.1.1 — 2015-01-27
- 0.1.0 — 2015-01-24

## README

# postcss-simple-extend [![Build Status](https://travis-ci.org/davidtheclark/postcss-simple-extend.svg?branch=master)](https://travis-ci.org/davidtheclark/postcss-simple-extend)

**A [PostCSS](https://github.com/postcss/postcss) plugin that enables you to extend placeholder selectors in CSS.**

Use this plugin to define a rule set with an abstract, extendable selector — a "placeholder selector" — to which you can, later on, add concrete selectors from other rule sets.

The functionality should mirror Sass's `@extend` with `%` placeholders (a.k.a. "silent classes").
Unlike Sass's `@extend`, however, *this plugin does not enable you to extend real selectors*: i.e. you cannot `@extend .classname` or `@extend ul > li + li > span a`.
That key difference makes this plugin *much* more simple, and arguably much less dangerous.
Many of the potential problems with Sass's `@extend` simply do not apply to this limited, more *simple* version. Smart Sass users often recommend to only ever `@extend` placeholders (cf. [Harry Robert](http://csswizardry.com/2014/01/extending-silent-classes-in-sass/) and [Hugo Giraudel](http://sass-guidelin.es/#extend)): *with this plugin, that recommendation is enforced*.

If you are looking for a more full-featured `@extend`, check out [`postcss-extend`](https://github.com/travco/postcss-extend).

> **A Note on "mixins" & "extends"**: Mixins copy declarations from an abstract definition into a concrete rule set. The simple extend supported by this plugin clones a concrete rule set's selector and adds it to an abstract placeholder selector. If you would like to use mixins, as well — or instead — have a look at [`postcss-mixins`](https://github.com/postcss/postcss-mixins).
>
> Also think about this: *Should* you use an `@extend` instead of a `@mixin`? The answer: *maybe not*. Given the fact that [`@extend`s don't actually reduce generated file size (after gzip)](https://tech.bellycard.com/blog/sass-mixins-vs-extends-the-data/), and the CSS generated by mixins is easier to read and understand, *you might not want to introduce `@extend`s to your codebase*. Just consider.

## Installation

```
npm install postcss-simple-extend --save
```

This plugin is compatible with PostCSS v4.1+.

## Example Input-Output

Input:
```css
@define-placeholder gigantic {
  font-size: 40em;
}

.foo {
  @extend gigantic;
  color: red;
}

.bar {
  @extend gigantic;
  color: orange;
}
```

Output:
```css
.foo,
.bar {
  font-size: 40em;
}

.foo {
  color: red;
}

.bar {
  color: orange;
}
```

## Usage

### Define Your Placeholder

With `@define-placeholder`, you associate a rule set with a placeholder selector, which you will later extend with concrete selectors.

You can also use `@define-extend` or `@simple-extend-define`, if either of those better fits your mind and situation.

```css
@define-placeholder simple-list {
  list-style-type: none;
  margin: 0;
  padding: 0;
}
/* or @define-extend simple-list {...} */
/* or @simple-extend-define simple-list {...} */
```

`@define-placeholder` at-rules, and the placeholder names (e.g. `simple-list`, above), will be removed entirely from the generated CSS, replaced by the selectors you've added via `@extend` (see example above).

There are some defining guidelines to obey (violations should log warnings):
- Definitions must occur at the root level (i.e. not inside statements, such as rule sets or `@media` blocks).
- Definitions should only contain declarations and comments: no statements.

### Extend a Placeholder (Add Selectors to It)

Use the at-rule `@extend` within a rule set to add that rule set's selector(s) to a placeholder (which was defined via `@define-placeholder`).

You can also use `@simple-extend-addto`, if that better fits your mind and situation.

```css
.list-i-want-to-be-simple {
  @extend simple-list;
  /* or @simple-extend-addto simple-list; */
  font-size: 40em;
}
```

And there are some `@extend` guidelines to obey (violations should log warnings):
- `@extend` must *not* occur at the root level: only inside rule sets.
- `@extend` must *not* occur within `@media` statements. (The generated code almost certainly would not match your intention.)
- The placeholder must be defined *before* `@extend` can refer to it.

### Plug it in to PostCSS

Plug it in just like any other PostCSS plugin. There are no frills and no options, so integration should be straightforward. For example (as a node script):

```js
var fs = require('fs');
var postcss = require('postcss');
var simpleExtend = require('postcss-simple-extend');

var inputCss = fs.readFileSync('input.css', 'utf8');

var outputCss = postcss()
  .use(simpleExtend())
  // or .use(simpleExtend)
  .process(inputCss)
  .css;

console.log(outputCss);
```

Or take advantage of [any of the myriad other ways to consume PostCSS](https://github.com/postcss/postcss#usage), and follow the plugin instructions they provide.

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