# prepend-selector-postcss

> PostCSS plugin Prepend selector for each rule. Optional exclude rules to prevent prepending 2021

Latest version **0.4.7** (published 2021-12-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install prepend-selector-postcss
pnpm add prepend-selector-postcss
yarn add prepend-selector-postcss
bun add prepend-selector-postcss
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.7 |
| Published | 2021-12-21 |
| First published | 2021-05-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 20.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | exsetnamor |
| Maintainers | filefabrik |
| Keywords | postcss, css, postcss-plugin, prefix exclude selector |

## Links

- npm: https://www.npmjs.com/package/prepend-selector-postcss
- Repository: https://github.com/filefabrik/prepend-selector-postcss
- Issues: https://github.com/filefabrik/prepend-selector-postcss/issues
- npm.io page: https://npm.io/package/prepend-selector-postcss

## Dependencies (1)

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

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

- 0.4.7 (latest) — 2021-12-21
- 0.4.6 — 2021-05-27
- 0.4.5 — 2021-05-27
- 0.4.4 — 2021-05-25
- 0.4.3 — 2021-05-20
- 0.4.2 — 2021-05-19
- 0.4.1 — 2021-05-19
- 0.4.0 — 2021-05-19

## README

# PostCSS Prepend Selector

[PostCSS] plugin Prepend selector for each rule with optional exclude existing selector from prepending.

[PostCSS]: Version 8 https://github.com/postcss/postcss


## The intention

The intention I had extended the plugin to create a user interface for the web using Vue-js and styled it with Tailwind-css. The Vue-js panel was
integrated into an existing website/application. So the styles created with Tailwind-css should be used exclusively in the Vue-js application.

That means this plugin is not really well developed. However, it serves its purpose without claiming to be a really well-tested script.

## Usage in postcss.config.js with  prepend-selector-postcss

```js
// postcss.config.js
const autoprefixer = require('autoprefixer');
const tailwindcss = require('tailwindcss');
// https://github.com/ledniy/postcss-prepend-selector
const prepend = require('prepend-selector-postcss')({
    // requiured
    selector: '.myPrefix ',
    // optional can be omitted
    exclude: ['.living_classname_to_prevent_from_prefixing '],
    // optional can be omitted
    excludePart: ['.grid-'],
    // optional can be omitted -> body{some unwanted global reset stuff}  -> body .selector{some unwanted global reset stuff}
    appendTo:['body'],
    // optional can be omitted -> Prefixing special selectors with a string that not exists in html tags to prevent using "body" - selector
    // body{some unwanted global reset stuff}  -> i_had_made_invalid_body{some unwanted global reset stuff}
    makeInvalid: {
        selectors:     ['body'],
        invalidPrefix: 'i_had_made_invalid_'
    }
})
module.exports = {
    purge  : [
        './public/**/*.html',
        './src/**/*.{js,jsx,ts,tsx,vue}',
    ],
    plugins: [
        tailwindcss,
        prepend,
        autoprefixer,
    ],
};
```

### Prefix all

```js
// minimal example
postcss([require('prepend-selector-postcss')({
    selector: '.myPrefix '
})])
```

Original Css

```css
.foo {
    /* Input example */
}

.foo, .bar {
    /* Input example */
}

```

Result

```css
.myPrefix .foo {
    /* Output example */
}

.myPrefix .foo, .myPrefix .bar {
    /* Output example */
}
```

### Prefix all but exclude something

```js
// example with exclude
postcss([require('prepend-selector-postcss')({
    selector: '.myPrefix ',
    exclude : ['#living_id_prefix_to_prevent_from_prefixing ', '.living_classname_to_prevent_from_prefixing '],
})])
```

Original Css

```css
.foo {
    /* Input example */
}

.foo, .bar {
    /* Input example */
}

#living_id_prefix_to_prevent_from_prefixing {
    /* Input example */
}

.living_classname_to_prevent_from_prefixing {
    /* Input example */
}

.living_classname_to_prevent_from_prefixing .somethingSub {
    /* Input example */
}
```

Result

```css
.myPrefix .foo {
    /* Output example */
}

.myPrefix .foo, .myPrefix .bar {
    /* Output example */
}

/* not prefixed */
#living_id_prefix_to_prevent_from_prefixing {
    /* Input example */
}

/* not prefixed */
.living_classname_to_prevent_from_prefixing {
    /* Input example */
}

/* not prefixed */
.living_classname_to_prevent_from_prefixing .somethingSub {
    /* Input example */
}
```

### Prefix all but exclude Start-With

```js

// exclude everything which starts with ".grid"
// excludes .grid-x | .grid .mySubClass
postcss([require('prepend-selector-postcss')({
    selector   : '.myPrefix ',
    excludePart: ['.grid']
})])
```

Original Css

```css
.foo {
    /* Input example */
}

.foo, .bar {
    /* Input example */
}

.grid .padding {
    /* Input example */
}

.grid-x .cell {
    /* Input example */
}
```

Result

```css
.myPrefix .foo {
    /* Output example */
}

.myPrefix .foo, .myPrefix .bar {
    /* Output example */
}

/* not prefixed */
.grid .padding {
    /* Input example */
}

/* not prefixed */
.grid-x .cell {
    /* Input example */
}
```

### All together

```js
// Full example
postcss([require('prepend-selector-postcss')({
    selector   : '.myPrefix ',
    exclude    : ['#living_id_prefix_to_prevent_from_prefixing ', '.living_classname_to_prevent_from_prefixing '],
    excludePart: ['.grid']
})])
```

Original Css

```css
.foo {
    /* Input example */
}

.foo, .bar {
    /* Input example */
}

#living_id_prefix_to_prevent_from_prefixing {
    /* Input example */
}

.living_classname_to_prevent_from_prefixing {
    /* Input example */
}

.living_classname_to_prevent_from_prefixing .somethingSub {
    /* Input example */
}

.grid .padding {
    /* Input example */
}

.grid-x .cell {
    /* Input example */
}
```

Result

```css
.myPrefix .foo {
    /* Output example */
}

.myPrefix .foo, .myPrefix .bar {
    /* Output example */
}

/* not prefixed */
#living_id_prefix_to_prevent_from_prefixing {
    /* Input example */
}

/* not prefixed */
.living_classname_to_prevent_from_prefixing {
    /* Input example */
}

/* not prefixed */
.living_classname_to_prevent_from_prefixing .somethingSub {
    /* Input example */
}

/* not prefixed */
.grid .padding {
    /* Input example */
}

/* not prefixed */
.grid-x .cell {
    /* Input example */
}
```

### Note

Please do not forget "selector" and "exclude" the space at the end of the string. exclude and excludePart are not tested. feel free to fork.

See [PostCSS] docs for examples for your environment.

### Forked from

https://github.com/ledniy/postcss-prepend-selector

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