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-include-media

v1.1.1

Published

PostCSS plugin to output @media definitions from include-media format.

Downloads

219

Readme

PostCSS Include Media

NPM version Tests

PostCSS plugin to output css @media definitions based on SASS mixin include-media format

Features

  • Flexible declaration of breakpoints
  • Smart support for media types
  • On-the-fly breakpoints
  • Supports most postcss plugins
  • Postcss nesting plugin is a dependency to allow nesting of rules

Contents

Install

Step 1: Install plugins:

npm install --save-dev postcss postcss-nesting postcss-include-media

Step 2: Check you project for existed PostCSS config: postcss.config.js in the project root, "postcss" section in package.json or postcss in bundle config.

If you do not use PostCSS, add it according to official docs and set this plugin in settings.

Step 3: Add the plugin to plugins list:

+ const postcssIncludeMedia = require('postcss-include-media');

module.exports = {
  plugins: [
+   require('postcss-nesting'),
+   postcssIncludeMedia(),
    require('autoprefixer')
  ]
}

Options

breakpoints

If you want to change them or add more, you can simply re-declare breakpoints using the Sass map syntax.

type Record<key: string>

optional: true

defaults:

{ phone: '320px', tablet: '768px', desktop: '1024px' }

usage:

postcssIncludeMedia({
    breakpoints: {
        md: '700px',
        xl: '1200px,
    }
}),

mediaExpressions

Media types and static expressions are optional and automatically deferred. The list of media types can be modified by declaring mediaExpressions.

Expressions containing logical disjunctions, such as Chris Coyier's retina declaration, are correctly handled, even when combined with other media types or breakpoints.

type Record<key: string>

optional: true

defaults:

{
    screen: 'screen',
    print: 'print',
    all: 'all',
    handheld: 'handheld',
    landscape: '(orientation: landscape)',
    portrait: '(orientation: portrait)',
    retina2x: '(-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi), (min-resolution: 2dppx)',
    retina3x: '(-webkit-min-device-pixel-ratio: 3), (min-resolution: 350dpi), (min-resolution: 3dppx)',
}

usage:

postcssIncludeMedia({
    mediaExpressions: {
        retina: '(-webkit-min-device-pixel-ratio: 2)',
    }
}),

unitIntervals

Defines a number to be added or subtracted from each unit when declaring breakpoints with inclusive/exclusive intervals

type Record<key: number>

optional: true

defaults:

{
    px: 1,
    em: 0.01,
    rem: 0.1,
    '': 0,
}

usage:

postcssIncludeMedia({
    unitIntervals: {
        '%': 1,
    }
}),

ruleName

Defines a the rule name you wish to use for the detection of breakpoints. EG for @include media('>phone') set ruleName: 'include media'. While this is supported by the plugin, its not recommended, as could cause issues with other plugins.

type string

optional: true

defaults:

'include-media'

usage:


// allows rules to be used
// @banana ('>=md') { .test { content: '' } }
postcssIncludeMedia({
    ruleName: 'banana'
}),

Examples

Input

@include-media('>=phone') {
    .foo {
        /* Input example */
    }
}

@include-media('<desktop') {
    .bar {
        /* Input example */
    }
}

Output

@media (min-width: 320px) {
    .foo {
        /* Output example */
    }
}

@media (max-width: 1023px) {
    .bar {
        /* Input example */
    }
}

Input

@include-media('>123px') {
    .foo {
        /* Input example */
    }
}

Output

@media (min-width: 124px) {
    .foo {
        /* Output example */
    }
}

Input

@include-media('>=desktop', 'retina2x') {
    .foo {
        /* Input example */
    }
}

Output

@media (min-width: 1024px) and (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi), (min-resolution: 2dppx)  {
    .foo {
        /* Output example */
    }
}

Credits

Credit to the original Authors of include-media both Eduardo Boucas and Kitty Giraudel