🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

postcss-variables-prefixer

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-variables-prefixer

postcss plugin to prefix all css custom properties

1.2.0
latest
Source
npm
Version published
Weekly downloads
367
-49.59%
Maintainers
1
Weekly downloads
 
Created
Source

postcss-variables-prefixer

Libraries.io dependency status for latest release License: MIT

PostCSS plugin to add a prefix to all css custom properties.

Usage

With PostCSS cli:

Install postcss, postcss-cli and postcss-variables-prefixer on your project directory:

npm install postcss postcss-cli postcss-variables-prefixer --save-dev

and in your package.json

"scripts": {
  "postcss": "postcss input.css -u postcss-variables-prefixer -o output.css"
}

Others

postcss([ require('postcss-variables-prefixer')({ /* options */ }) ])

Options

prefix

Type: string
Default: none

String to be used as prefix

ignore

Type: array
Default: []

Array of css custom properties to be ignored by the plugin, accepts string and regex.

Example

Example of usage with results generated by the plugin.

Code

const postcss = require('postcss');
const prefixer = require('postcss-variables-prefixer');

const input = fs.readFileSync('path/to/file.css',  'utf-8');

const output = postcss([
  prefixer({
        prefix: 'prefix-',
        ignore: [ /bar/, '--ignore' ]
    })
]).process(input);

Input:

:root {
  --foo: red;
  --foo-bar: green;
  --ignore: 300px;
  --not-ignored: 100px;
  --bar: yellow;
}

div {
  background-color: var(--foo);
  color: var(--foo-bar);
  width: var(--ignore);
  height: var(--not-ignored);
  border-color: var(--bar)
}

Output:

:root {
  --prefix-foo: red;
  --foo-bar: green;
  --ignore: 300px;
  --prefix-not-ignored: 100px;
  --bar: yellow;
}

div {
  background-color: var(--prefix-foo);
  color: var(--foo-bar);
  width: var(--ignore);
  height: var(--prefix-not-ignored);
  border-color: var(--bar)
}

Credits

Plugin inspired by postcss-prefixer created by marceloucker.

Thanks to Andrey Sitnik @ai and Jonathan Neal @jonathantneal for the help.

Keywords

css

FAQs

Package last updated on 27 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts