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

grunt-match-media

v0.1.0

Published

Grunt plugin to extract styles matching certain viewport width conditions, and create separate stylesheets with them

Downloads

2

Readme

grunt-match-media

NPM version NPM Downloads Dependencies Dev Dependencies Build Status

Grunt wrapper for node-match-media - plugin to extract styles matching certain media conditions, and create separate stylesheets with them

Getting Started

This plugin requires Grunt ~0.4.5

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-match-media --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-match-media');

The "match_media" task

Overview

In your project's Gruntfile, add a section named match_media to the data object passed into grunt.initConfig().

grunt.initConfig({
  match_media: {
    my_task: {
      options: {
        // Task-specific options go here.
      },
      your_target: {
        // Target-specific file lists and/or options go here.
      }
    }
  }
});

Options

options.width

Type: String Default value: '960px'

The viewport width for media queries to be evaluated against (in em or px).

options.height

Type: String Default value: '768px'

The viewport height for media queries to be evaluated against (in em or px).

options.px_em_ratio

Type: Integer Default value: 16

How many px to treat 1em as (by default 1em is treated as 16px)

options.orientation

Type: String Default value: undefined

What orientation queries to match, options are 'landscape', 'portrait', or 'both'

options.with_queries

Type: Boolean Default value: false

Preserves the media statements in the output CSS (default option is to write the styles without the query). This new option is useful for creating stylesheets for specific device ranges (but still have media queries within them).

options.always_match

Type: Array of Strings Default value: []

In case any options you require aren't covered by the task yet, you can pass a list of query types in to always match, whatever their value. Eg: ['min-device-pixel-ratio']

Usage Examples

Default Options

In this example, the styles from styles.css then other-styles.css are evaluated and any media queries which would apply in a 960px width browser are written into desktop-syles.css.

grunt.initConfig({
  match_media: {
    desktop: {
      files: {
        'desktop-styles.css': ['styles.css', 'other-styles.css']
      }
    }
  }
});

Custom Options

In this example, the styles from styles.css then other-styles.css are evaluated and any media queries which would apply in a 20em (or 20em * 16px = 320px) width browser are written into mobile-syles.css.

grunt.initConfig({
  match_media: {
    mobile: {
      options: {
        width: '20em',
        px_em_ratio: 16,
        orientation: 'portrait',
        always_match: [
          'min-device-pixel-ratio'
        ],
        with_queries: true
      },
      files: {
        'mobile-styles.css': ['styles.css', 'other-styles.css']
      }
    }
  }
});

Contributing

All of the functionality is now contained in the node-match-media project so any contributions may be more appropriate there.

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

  • 0.1.0 Abstracting main functionality into node-match-media project
  • 0.0.7 Supporting `orientation``queries (thanks for the nudge zeorin), and an option to always match certain queries
  • 0.0.6 New with_queries option added (thanks to lukaszzdanikowski for working on this)
  • 0.0.5 Support for device sized media queries to map to the appropriate min/max width, extended to support height-based media queries
  • 0.0.4 Support for and and , in statements, as well as a binary check between print and all other media types
  • 0.0.3 Small bugfixes
  • 0.0.2 Support for using em and px with a conversion between the two
  • 0.0.1 Basic functionality