All Projects → ChristianMurphy → postcss-combine-duplicated-selectors

ChristianMurphy / postcss-combine-duplicated-selectors

Licence: MIT License
automatically keep css selectors unique.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
shell
77523 projects

Projects that are alternatives of or similar to postcss-combine-duplicated-selectors

postcss-define-function
PostCSS plugin for Sass-like function directive
Stars: ✭ 25 (-63.77%)
Mutual labels:  postcss
react-cli
基于 create-react-app 搭建的前端脚手架
Stars: ✭ 18 (-73.91%)
Mutual labels:  postcss
tailwind-bootstrap-grid
Tailwind CSS plugin that generates Bootstrap's flexbox grid
Stars: ✭ 96 (+39.13%)
Mutual labels:  postcss
aik
Frontend Playground
Stars: ✭ 43 (-37.68%)
Mutual labels:  postcss
stencil-tailwind-plugin
Plugin for using tailwindcss with StencilJS
Stars: ✭ 17 (-75.36%)
Mutual labels:  postcss
vite-ts-tailwind-starter
Opinionated Vite + Vue 3 + TypeScript + Tailwind CSS starter template w/ tests and CI.
Stars: ✭ 228 (+230.43%)
Mutual labels:  postcss
postcss-clean
PostCss plugin to minify your CSS with clean-css
Stars: ✭ 41 (-40.58%)
Mutual labels:  postcss
hugo-starter-tailwind-basic
A basic and simple to set up Hugo with TailwindCSS starter project.
Stars: ✭ 80 (+15.94%)
Mutual labels:  postcss
webpack-typescript-react
Webpack 5 boilerplate with support of most common loaders and modules (see tags and description)
Stars: ✭ 185 (+168.12%)
Mutual labels:  postcss
ying-template
这是一个基于 `webpack@^5.27.2` + `typescript@^4.2.3` + `@babel/core@^7.2.2` + `jest@^26.6.3` + `eslint@^7.22.0` 的多页面脚手架。
Stars: ✭ 125 (+81.16%)
Mutual labels:  postcss
postcss-aspect-ratio
A PostCSS plugin to fix an element's dimensions to an aspect ratio.
Stars: ✭ 38 (-44.93%)
Mutual labels:  postcss
postcss-sort-media-queries
PostCSS plugin for combine and sort CSS media queries with mobile first or desktop first methods.
Stars: ✭ 118 (+71.01%)
Mutual labels:  postcss
postcss-bidirection
PostCSS plugin that polyfill Bi-directional CSS properties and values to suppot rtl and ltr rules in all browsers
Stars: ✭ 24 (-65.22%)
Mutual labels:  postcss
postcss-typed-css-classes
PostCSS plugin that generates typed entities from CSS classes for chosen programming language.
Stars: ✭ 12 (-82.61%)
Mutual labels:  postcss
building-realworld-user-interfaces-using-tailwind
Demo of building real-world UIs using TailwindCSS
Stars: ✭ 87 (+26.09%)
Mutual labels:  postcss
Bootstrap4-RTL
🅱 An Awesome RTL bootstrap 4 with gulp and postcss
Stars: ✭ 89 (+28.99%)
Mutual labels:  postcss
tailwindcss-postcss-browsersync-boilerplate
Tailwind CSS + PostCSS + BrowserSync boilerplate
Stars: ✭ 28 (-59.42%)
Mutual labels:  postcss
postcss-shopify-settings-variables
PostCSS plugin for variable of theme setting in shopify css file.
Stars: ✭ 14 (-79.71%)
Mutual labels:  postcss
caesura
📏 A reasonable breakpoint scale using @Custom-Media
Stars: ✭ 14 (-79.71%)
Mutual labels:  postcss
meteor-postcss
PostCSS for Meteor
Stars: ✭ 68 (-1.45%)
Mutual labels:  postcss

Postcss combine duplicated selectors

npm build status dependency status devDependency status

Automatically detects and combines duplicated css selectors so you don't have to 😄

Usage

Requirements

In order to use this you will need to have postcss installed. Depending on whether or not you want to use the CLI you need to install postcss-cli.

npm install --save-dev postcss postcss-combine-duplicated-selectors
# or
yarn add --dev postcss postcss-combine-duplicated-selectors

Using PostCSS JS API

'use strict';

const fs = require('fs');
const postcss = require('postcss');
const css = fs.readFileSync('src/app.css');

postcss([require('postcss-combine-duplicated-selectors')])
    .process(css, {from: 'src/app.css', to: 'app.css'})
    .then((result) => {
      fs.writeFileSync('app.css', result.css);
      if (result.map) fs.writeFileSync('app.css.map', result.map);
    });

Using PostCSS CLI

postcss style.css --use postcss-combine-duplicated-selectors --output newcss.css

Example

Input

.module {
  color: green;
}
.another-module {
  color: blue;
}
.module {
  background: red;
}
.another-module {
  background: yellow;
}

Output

.module {
  color: green;
  background: red;
}
.another-module {
  color: blue;
  background: yellow;
}

Duplicated Properties

Duplicated properties can optionally be combined.

Set the removeDuplicatedProperties option to true to enable.

const postcss = require('postcss');
const combineSelectors = require('postcss-combine-duplicated-selectors');

postcss([combineSelectors({removeDuplicatedProperties: true})]);

When enabled the following css

.a {
  height: 10px;
  background: orange;
  background: rgba(255, 165, 0, 0.5);
}

will combine into

.a {
  height: 10px;
  background: rgba(255, 165, 0, 0.5);
}

In order to limit this to only combining properties when the values are equal, set the removeDuplicatedValues option to true instead. This could clean up duplicated properties, but allow for conscious duplicates such as fallbacks for custom properties.

const postcss = require('postcss');
const combineSelectors = require('postcss-combine-duplicated-selectors');

postcss([combineSelectors({removeDuplicatedValues: true})]);

This will transform the following css

.a {
  height: 10px;
}

.a {
  width: 20px;
  background: var(--custom-color);
  background: rgba(255, 165, 0, 0.5);
}

into

.a {
  height: 10px;
  width: 20px;
  background: var(--custom-color);
  background: rgba(255, 165, 0, 0.5);
}

Media Queries

If you have code with media queries, pass code through postcss-combine-media-query or css-mquery-packer before postcss-combine-duplicated-selectors to ensure optimal results.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].