JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 591412
  • Score
    100M100P100Q194275F
  • License MIT

The custom `sort` method (mobile-first) of CSS media queries for `css-mqpacker` or `pleeease` (which uses css-mqpacker) or, perhaps, something else ))

Package Exports

  • sort-css-media-queries

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sort-css-media-queries) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

sort-css-media-queries

npm es2015 license Build Status

🇺🇸 English | 🇷🇺 Русский язык

The custom sort method (mobile-first) for css-mqpacker or pleeease (which uses css-mqpacker) or, perhaps, something else ))

js happiness style

Installing

npm install --save sort-css-media-queries
# or using yarn cli
yarn add sort-css-media-queries

Usage

See the original docs at first https://www.npmjs.com/package/css-mqpacker#sort;

const sortCSSmq = require('sort-css-media-queries');

// your cool code
// ...

postcss([
  mqpacker({
    sort: sortCSSmq
  })
]).process(css);

mobile-first

The plugin will sort your media-queries according to the mobile-first methodology. The sequence of media requests:

  1. min-width and min-height from smallest to largest,
  2. max-width and max-height from largest to smallest,
  3. min-device-width and min-device-height from smallest to largest,
  4. max-device-width and max-device-height from largest to smallest
  5. media queries without dimension values, for example print, tv, ....

Example

Media-queries list:

// min-width/-height -> from smallest to largest
'only screen and (min-width: 320px) and (max-width: 767px)',
'screen and (min-height: 480px)',
'screen and (min-height: 480px) and (min-width: 320px)',
'only screen and (min-width: 640px)',
'screen and (min-width: 1024px)',
'only screen and (min-width: 1280px)',

// device
'only screen and (min-device-width: 320px) and (max-device-width: 767px)',

// max-width/-height <- from largest to smallest
'only screen and (max-width: 1023px)',
'only screen and (max-height: 767px) and (min-height: 320px)',
'only screen and (max-width: 767px) and (min-width: 320px)',
'screen and (max-width: 639px)',

// no units
'only screen and (orientation: landscape)',
'only screen and (orientation: portrait)',
'print',
'tv'

Sort result:

'only screen and (min-width: 320px) and (max-width: 767px)',
'screen and (min-height: 480px)',
'screen and (min-height: 480px) and (min-width: 320px)',
'only screen and (min-width: 640px)',
'screen and (min-width: 1024px)',
'only screen and (min-width: 1280px)',
'only screen and (min-device-width: 320px) and (max-device-width: 767px)',
'only screen and (max-width: 1023px)',
'only screen and (max-height: 767px) and (min-height: 320px)',
'only screen and (max-width: 767px) and (min-width: 320px)',
'screen and (max-width: 639px)',
'only screen and (orientation: landscape)',
'only screen and (orientation: portrait)',
'print',
'tv'

Tests

  1. npm run sort - test of sorting result
  2. npm run happiness - test code style
  3. npm test: npm run sort + npm run happiness

Project Info