Socket
Socket
Sign inDemoInstall

postcss-discard-duplicates

Package Overview
Dependencies
4
Maintainers
8
Versions
47
Alerts
File Explorer

Advanced tools

Install Socket

Protect your apps from supply chain attacks

Install

postcss-discard-duplicates

Discard duplicate rules in your CSS files with PostCSS.

    6.0.2latest
    GitHub
    npm

Version published
Maintainers
8
Weekly downloads
11,535,139
increased by2.92%

Weekly downloads

Package description

What is postcss-discard-duplicates?

The postcss-discard-duplicates package is a PostCSS plugin designed to remove duplicate rules, declarations, and @rules from your CSS. This helps in reducing the file size and cleaning up the CSS for better performance and readability.

What are postcss-discard-duplicates's main functionalities?

Discard duplicate rules

This feature removes duplicate CSS rules. If two or more rules are identical, only one is kept.

"const postcss = require('postcss');
const discardDuplicates = require('postcss-discard-duplicates');

postcss([ discardDuplicates() ])
.process('a { color: black; } a { color: black; }', { from: undefined })
.then(result => {
  console.log(result.css);
  // Output: 'a { color: black; }'
});"

Discard duplicate declarations within a rule

This feature removes duplicate declarations within a single rule, keeping only one instance of the declaration.

"const postcss = require('postcss');
const discardDuplicates = require('postcss-discard-duplicates');

postcss([ discardDuplicates() ])
.process('a { color: black; color: black; }', { from: undefined })
.then(result => {
  console.log(result.css);
  // Output: 'a { color: black; }'
});"

Discard duplicate @rules

This feature removes duplicate @rules from the CSS, ensuring that only one instance of each @rule is present.

"const postcss = require('postcss');
const discardDuplicates = require('postcss-discard-duplicates');

postcss([ discardDuplicates() ])
.process('@font-face { font-family: 'MyFont'; src: url('myfont.woff2'); }
@font-face { font-family: 'MyFont'; src: url('myfont.woff2'); }', { from: undefined })
.then(result => {
  console.log(result.css);
  // Output: '@font-face { font-family: 'MyFont'; src: url('myfont.woff2'); }'
});"

Other packages similar to postcss-discard-duplicates

Readme

Source

postcss-discard-duplicates

Discard duplicate rules in your CSS files with PostCSS.

Install

With npm do:

npm install postcss-discard-duplicates --save

Example

This module will remove all duplicate rules from your stylesheets. It works on at rules, normal rules and declarations. Note that this module does not have any responsibility for normalising declarations, selectors or whitespace, so that it considers these two rules to be different:

h1, h2 {
    color: blue;
}

h2, h1 {
    color: blue;
}

It has to assume that your rules have already been transformed by another processor, otherwise it would be responsible for too many things.

Input

h1 {
    margin: 0 auto;
    margin: 0 auto
}

h1 {
    margin: 0 auto
}

Output

h1 {
    margin: 0 auto
}

Usage

See the PostCSS documentation for examples for your environment.

Contributors

See CONTRIBUTORS.md.

License

MIT © Ben Briggs

Keywords

FAQs

Last updated on 22 Feb 2024

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

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