npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

postcss-combine-media-query

v1.0.1

Published

PostCSS plugin to combine equal media query rules.

Downloads

42,760

Readme

postcss-combine-media-query

Build Status

If you are used to write the media queries of your components within those components (what you should do instead of maintaining a large global media query file) you might end up with CSS that contains the same media query rule multiple times.

.foo { color: red; }
@media (min-width: 1024px) {
    .foo { color: green; }
}
.bar { font-size: 1rem; }
@media (min-width: 1024px) {
    .bar { font-size: 2rem; }
}

While this is totally fine in development (and supports a modular structure in particular when using Sass) it's not that good for production where you wanna keep your CSS as small as possible.

That's the use case this plugin is built for! It looks for equal media query rules and appends them combined.

.foo { color: red; }
.bar { font-size: 1rem; }
@media (min-width: 1024px) {
    .foo { color: green; }
    .bar { font-size: 2rem; }
}

Installation

  • npm
npm install postcss-combine-media-query --save-dev
  • yarn
yarn add postcss-combine-media-query --dev

Usage

Simply add the plugin to your PostCSS config. That's all – easy as pie :wink: (there are no options)

If you're not familiar with using PostCSS you should read the official PostCSS documentation first.

Side Effects

Since this plugin moves all media queries to end of the file it may introduce bugs if your CSS is not well structured. So keep that in mind!

Let's say you've got the following code which results in .foo being yellow on desktop.

.foo { color: red; }
@media (min-width: 1024px) {
    .foo { color: green; }
}
.foo { color: yellow; }

Once you use this plugin it will change into green because the media query has been moved.

.foo { color: red; }
.foo { color: yellow; }
@media (min-width: 1024px) {
    .foo { color: green; }
}

Therefore it's recommended to use this plugin in development as well to detect such side effects sooner.

Credits

If this plugin is helpful to you it'll be great when you give me a star on github and share it. Keeps me motivated to continue the development.