Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

postcss-custom-properties

Package Overview
Dependencies
1
Maintainers
4
Versions
66
Issues
File Explorer

Advanced tools

postcss-custom-properties

Use Custom Properties Queries in CSS

    12.1.11latest

Version published
Maintainers
4
Weekly downloads
6,044,140
decreased by-22.9%

Weekly downloads

Readme

Source

PostCSS Custom Properties PostCSS

NPM Version CSS Standard Status Build Status Discord

PostCSS Custom Properties lets you use Custom Properties in CSS, following the CSS Custom Properties specification.

'Can I use' table

:root { --color: red; } h1 { color: var(--color); } /* becomes */ :root { --color: red; } h1 { color: red; color: var(--color); }

Note: This plugin only processes variables that are defined in the :root selector.

Usage

Add PostCSS Custom Properties to your project:

npm install postcss-custom-properties --save-dev

Use PostCSS Custom Properties as a PostCSS plugin:

const postcss = require('postcss'); const postcssCustomProperties = require('postcss-custom-properties'); postcss([ postcssCustomProperties(/* pluginOptions */) ]).process(YOUR_CSS /*, processOptions */);

PostCSS Custom Properties runs in all Node environments, with special instructions for:

NodePostCSS CLIWebpackCreate React AppGulpGrunt

Options

preserve

The preserve option determines whether Custom Properties and properties using custom properties should be preserved in their original form. By default, both of these are preserved.

postcssCustomProperties({ preserve: false }); :root { --color: red; } h1 { color: var(--color); } /* becomes */ h1 { color: red; }

importFrom

The importFrom option specifies sources where Custom Properties can be imported from, which might be CSS, JS, and JSON files, functions, and directly passed objects.

postcssCustomProperties({ importFrom: 'path/to/file.css' // => :root { --color: red } }); h1 { color: var(--color); } /* becomes */ h1 { color: red; }

Multiple sources can be passed into this option, and they will be parsed in the order they are received. JavaScript files, JSON files, functions, and objects will need to namespace Custom Properties using the customProperties or custom-properties key.

postcssCustomProperties({ importFrom: [ 'path/to/file.css', // :root { --color: red; } 'and/then/this.js', // module.exports = { customProperties: { '--color': 'red' } } 'and/then/that.json', // { "custom-properties": { "--color": "red" } } { customProperties: { '--color': 'red' } }, () => { const customProperties = { '--color': 'red' }; return { customProperties }; } ] });

See example imports written in CSS, JS, and JSON.

overrideImportFromWithRoot

The overrideImportFromWithRoot option determines if properties added via importFrom are overridden by properties that exist in :root. Defaults to false.

postcssCustomProperties({ overrideImportFromWithRoot: true });

exportTo

The exportTo option specifies destinations where Custom Properties can be exported to, which might be CSS, JS, and JSON files, functions, and directly passed objects.

postcssCustomProperties({ exportTo: 'path/to/file.css' // :root { --color: red; } });

Multiple destinations can be passed into this option, and they will be parsed in the order they are received. JavaScript files, JSON files, and objects will need to namespace Custom Properties using the customProperties or custom-properties key.

const cachedObject = { customProperties: {} }; postcssCustomProperties({ exportTo: [ 'path/to/file.css', // :root { --color: red; } 'and/then/this.js', // module.exports = { customProperties: { '--color': 'red' } } 'and/then/this.mjs', // export const customProperties = { '--color': 'red' } } 'and/then/that.json', // { "custom-properties": { "--color": "red" } } 'and/then/that.scss', // $color: red; cachedObject, customProperties => { customProperties // { '--color': 'red' } } ] });

See example exports written to CSS, JS, MJS, JSON and SCSS.

disableDeprecationNotice

Silence the deprecation notice that is printed to the console when using importFrom or exportTo.

"importFrom" and "exportTo" will be removed in a future version of postcss-custom-properties. Check the discussion on github for more details. https://github.com/csstools/postcss-plugins/discussions/192

Keywords

FAQs

What is postcss-custom-properties?

Use Custom Properties Queries in CSS

Is postcss-custom-properties popular?

The npm package postcss-custom-properties receives a total of 5,034,003 weekly downloads. As such, postcss-custom-properties popularity was classified as popular.

Is postcss-custom-properties well maintained?

We found that postcss-custom-properties demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 4 open source maintainers collaborating on the project.

Last updated on 01 Dec 2022

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc