Closed tohuw closed 7 years ago
Whoops, my .postcssrc.json:
{
"properties-order": [
"margin",
"padding",
"border",
"background"
]
}
postcss-sorting is v4.1.1, by the way.
Why you think that postcss-sorting
supports config in the .postcssrc.json
file?
Sorry, maybe it provided by postcss.
@mrmlnc I'm not confident of the syntax of the sorting file, and welcome any commentary on that also. Right now, I just can't get your VSCode plugin, or postcss-sorting itself via CLI, to work at all. Any help is appreciated. Thanks!
Enhanced the test case a bit:
test.css
body {
border: 1px solid purple;
background-color: red;
font-size: 1em;
margin-right: 2rem;
line-height: 4;
display: block;
}
sort.json
{
"order": [
"custom-properties",
"dollar-variables",
"declarations",
"at-rules",
"rules"
],
"properties-order": "alphabetical",
"unspecified-properties-position": "bottom"
}
postcss -u postcss-sorting -c sort.json --no-map -r test.css
The file does not change, even though postcss returns an exit code 0. Conversely, something like the below does what it should:
postcss -u cssnano --no-map -r test.css
@tohuw I never used PostCSS CLI, but I see your config is not what PostCSS CLI expects. Please, take a look at its documentation.
Ack, you're completely right, of course. I thought I could simply pass the options for your relevant plugins to it, but I now realize I need a formal structure (which made plenty of sense when I RTFM). It works now, thanks so much!
This is a working css sort test with postcss-cli
:
test.css
body {
border: 1px solid purple;
background-color: red;
font-size: 1em;
margin-right: 2rem;
line-height: 4;
display: block;
}
postcss.config.js
module.exports = (ctx) => ({
plugins: {
'postcss-sorting': {
'order': [
'custom-properties',
'dollar-variables',
'declarations',
'at-rules',
'rules'
],
'properties-order': 'alphabetical',
'unspecified-properties-position': 'bottom'
}
}
})
postcss -c postcss.config.js --no-map -r test.css
@tohuw would you mind creating a documentation PR for using this plugin via PostCSS CLI, please? It would help other users.
Per #42, it isn't clear how to use this command via CLI. I tried the following, and no sorting occurred in my test file:
Test file: