Socket
Socket
Sign inDemoInstall

postcss-merge-rules

Package Overview
Dependencies
17
Maintainers
8
Versions
74
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    postcss-merge-rules

Merge CSS rules with PostCSS.


Version published
Weekly downloads
11M
Maintainers
8
Created
Weekly downloads
 

Package description

What is postcss-merge-rules?

The postcss-merge-rules npm package is designed to optimize CSS by merging CSS rules with identical selectors or declarations. This can lead to smaller CSS files and potentially faster load times for web pages.

What are postcss-merge-rules's main functionalities?

Merging based on identical selectors

This feature combines rules with identical selectors into a single rule. In the code sample, two rules for the 'a' selector are merged into one.

const postcss = require('postcss');
const mergeRules = require('postcss-merge-rules');

const css = `a { color: blue; }
a { font-size: 14px; }`;

postcss([mergeRules()])
.process(css, { from: undefined })
.then(result => console.log(result.css));

Merging based on identical declarations

This feature merges rules that have identical declarations but different selectors, creating a grouped selector. The code sample demonstrates merging two rules that apply the same color declaration to different selectors.

const postcss = require('postcss');
const mergeRules = require('postcss-merge-rules');

const css = `a { color: blue; }
b { color: blue; }`;

postcss([mergeRules()])
.process(css, { from: undefined })
.then(result => console.log(result.css));

Other packages similar to postcss-merge-rules

Readme

Source

postcss-merge-rules

Merge CSS rules with PostCSS.

Install

With npm do:

npm install postcss-merge-rules --save

Examples

This module will attempt to merge adjacent CSS rules:

By declarations

Input
a {
    color: blue;
    font-weight: bold
}

p {
    color: blue;
    font-weight: bold
}
Output
a,p {
    color: blue;
    font-weight: bold
}

By selectors

Input
a {
    color: blue
}

a {
    font-weight: bold
}
Output
a {
    color: blue;
    font-weight: bold
}

By partial declarations

Input
a {
    font-weight: bold
}

p {
    color: blue;
    font-weight: bold
}
Output
a,p {
    font-weight: bold
}

p {
    color: blue
}

Usage

See the PostCSS documentation for examples for your environment.

Contributors

See CONTRIBUTORS.md.

License

MIT © Ben Briggs

Keywords

FAQs

Last updated on 24 Apr 2024

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc