Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
postcss-sort-media-queries
Advanced tools
PostCSS plugin for combine and sort CSS media queries with mobile first or desktop first methods.
The postcss-sort-media-queries package is a PostCSS plugin that sorts CSS media queries. It helps in organizing media queries in a specific order, which can be useful for maintaining a clean and efficient stylesheet.
Sort Media Queries by Width
This feature sorts media queries in a mobile-first order, meaning smaller screen sizes will be prioritized over larger ones.
module.exports = {
plugins: [
require('postcss-sort-media-queries')({
sort: 'mobile-first'
})
]
};
Sort Media Queries by Custom Order
This feature sorts media queries in a desktop-first order, meaning larger screen sizes will be prioritized over smaller ones.
module.exports = {
plugins: [
require('postcss-sort-media-queries')({
sort: 'desktop-first'
})
]
};
Sort Media Queries by Specific Criteria
This feature allows you to sort media queries based on a custom function, providing flexibility in how media queries are ordered.
module.exports = {
plugins: [
require('postcss-sort-media-queries')({
sort: function(a, b) {
return a.localeCompare(b);
}
})
]
};
css-mqpacker is a PostCSS plugin that packs same CSS media query rules into one media query rule. Unlike postcss-sort-media-queries, which focuses on sorting, css-mqpacker focuses on merging media queries to reduce redundancy.
postcss-combine-media-query is a PostCSS plugin that combines matching media queries into one. It is similar to css-mqpacker but with a focus on combining rather than sorting.
postcss-merge-rules is a PostCSS plugin that merges adjacent rules by selectors and properties. While it doesn't specifically target media queries, it can help in reducing the overall size of the CSS by merging rules, which can indirectly affect media queries.
PostCSS plugin for combine and sort CSS media queries with mobile first or desktop first methods.
Combine same media queries into one - is a unexpected side effect for this plugin 🧬
/* before */
@media screen and (max-width: 640px) {
.head { color: #cfcfcf }
}
@media screen and (max-width: 768px) {
.footer { color: #cfcfcf }
}
@media screen and (max-width: 640px) {
.main { color: #cfcfcf }
}
@media screen and (min-width: 1280px) {
.mobile-first { color: #cfcfcf }
}
@media screen and (min-width: 640px) {
.mobile-first { color: #cfcfcf }
}
@media screen and (max-width: 640px) {
.footer { color: #cfcfcf }
}
/* after */
@media screen and (min-width: 640px) {
.mobile-first { color: #cfcfcf }
}
@media screen and (min-width: 1280px) {
.mobile-first { color: #cfcfcf }
}
@media screen and (max-width: 768px) {
.footer { color: #cfcfcf }
}
@media screen and (max-width: 640px) {
.head { color: #cfcfcf }
.main { color: #cfcfcf }
.footer { color: #cfcfcf }
}
/* before */
@media screen and (max-width: 640px) {
.header { color: #cdcdcd }
}
@media screen and (min-width: 760px) {
.desktop-first { color: #cdcdcd }
}
@media screen and (max-width: 640px) {
.main { color: #cdcdcd }
}
@media screen and (min-width: 1280px) {
.desktop-first { color: #cdcdcd }
}
@media screen and (max-width: 760px) {
.footer { color: #cdcdcd }
}
@media screen and (max-width: 640px) {
.footer { color: #cdcdcd }
}
/* after */
@media screen and (max-width: 760px) {
.footer { color: #cdcdcd }
}
@media screen and (max-width: 640px) {
.header { color: #cdcdcd }
.main { color: #cdcdcd }
.footer { color: #cdcdcd }
}
@media screen and (min-width: 760px) {
.desktop-first { color: #cdcdcd }
}
@media screen and (min-width: 1280px) {
.desktop-first { color: #cdcdcd }
}
First thing's, install the module:
npm install postcss postcss-sort-media-queries --save-dev
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 already use PostCSS, add the plugin to plugins list:
module.exports = {
plugins: [
+ require('postcss-sort-media-queries')({
+ // sort: 'mobile-first' default value
+ sort: function(a, b) {
+ // custom sorting function
+ }
+ }),
require('autoprefixer')
]
}
If you do not use PostCSS, add it according to official docs and set this plugin in settings.
Sorting works based on dutchenkoOleg/sort-css-media-queries function.
This option support string or function values.
{string}
'mobile-first'
- (default) mobile first sorting{string}
'desktop-first'
- desktop first sorting{function}
your own sorting function'mobile-first'
postcss([
sortMediaQueries({
sort: 'mobile-first' // default
})
]).process(css);
'desktop-first'
postcss([
sortMediaQueries({
sort: 'desktop-first'
})
]).process(css);
postcss([
sortMediaQueries({
function(a, b) {
return a.localeCompare(b);
}
})
]).process(css);
In this example, all your media queries will sort by A-Z order.
This sorting function is directly passed to Array#sort() method of an array of all your media queries.
See Releases history
postcss-momentum-scrolling
- plugin for adding momentum style scrolling behavior (-webkit-overflow-scrolling:touch
) for elements with overflow (scroll, auto) on iOS[3.10.11] 2021-05-18
list
type definitionsFAQs
PostCSS plugin for sorting and combining CSS media queries with mobile first / **desktop first methodologies
The npm package postcss-sort-media-queries receives a total of 259,253 weekly downloads. As such, postcss-sort-media-queries popularity was classified as popular.
We found that postcss-sort-media-queries demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.