-
Sorts rules and at-rules content. -
Sorts properties. -
Sorts at-rules by different options. -
Groups properties, custom properties, dollar variables, nested rules, nested at-rules. -
Supports CSS, SCSS (using postcss-scss ), CSS-in-JS (with postcss-styled-syntax ), HTML (with postcss-html ), and most likely any other syntax added by other PostCSS plugins.
npm install --save-dev postcss postcss-sorting
order : Specify the order of content within declaration blocks. properties-order : Specify the order of properties within declaration blocks. unspecified-properties-position : Specify position for properties not specified in properties-order . throw-validate-errors : Throw config validation errors instead of showing and ignoring them. Defaults to false .
a { top : five px ; /* shared-line comment belongs to `top` */
/* comment belongs to `bottom` */
/* comment belongs to `bottom` */
bottom : fifteen px ; /* shared-line comment belongs to `bottom` */ }
const Component = styled . div `
/* The following properties WILL NOT be sorted, because interpolation is on properties level */
z-index: 1;
top: 1px;
${ props => props . great && 'color: red' } ;
position: absolute;
display: block;
div {
/* The following properties WILL be sorted, because interpolation for property value only */
z-index: 2;
position: static;
top: ${ two + ten } px;
display: inline-block;
}
` ;
npm install postcss postcss-cli postcss-sorting --save-dev
module . exports = {
plugins : {
'postcss-sorting' : {
order : [
'custom-properties' ,
'dollar-variables' ,
'declarations' ,
'at-rules' ,
'rules' ,
] ,
'properties-order' : 'alphabetical' ,
'unspecified-properties-position' : 'bottom' ,
} ,
} ,
} ;
npx postcss --no-map --replace your-css-file.css
npm install postcss gulp-postcss postcss-sorting --save-dev
let gulp = require ( 'gulp' ) ;
let postcss = require ( 'gulp-postcss' ) ;
let sorting = require ( 'postcss-sorting' ) ;
exports [ 'sort-css' ] = ( ) => {
return gulp
. src ( './ css/src/*.css' )
. pipe (
postcss ( [
sorting ( {
/* options */
} ) ,
] )
)
. pipe ( gulp . dest ( './ css/src' ) ) ;
} ;