[英]cssnano is reordering overridden properties
I am using less, postcss and cssnano (version 3.7.3).我正在使用 less、postcss 和 cssnano(版本 3.7.3)。 In less, I am using classes which inherit from a shared base and overriding some of the properties when needed.在更少的情况下,我使用从共享基类继承的类,并在需要时覆盖一些属性。 I am finding that cssnano is reordering the inherited\overridden properties causing unexpected differences in the style.我发现 cssnano 正在重新排序继承\覆盖的属性,导致样式出现意外差异。
A trimmed down example .less looks like this:精简后的示例 .less 如下所示:
.cell-label {
font-size: 11px;
}
.heading-label-cell {
.cell-label;
color: @heading-colour;
font-size: 13px;
}
.question-label-cell {
.cell-label;
color: @question-colour;
}
Which is then expanded to css looking like:然后将其扩展为 css,如下所示:
.heading-label-cell {
font-size: 11px;
font-size: 13px;
color:#616161;
}
.question-label-cell {
font-size: 11px;
color: #0073d6;
}
But cssnano then does the following which has reordered the font-size property:但是 cssnano 然后执行以下操作,重新排序了 font-size 属性:
.heading-label-cell {
color:#616161;
font-size:13px
}
.heading-label-cell,.question-label-cell {
font-size:11px;
}
.question-label-cell {
color:#0073d6
}
Is there a different way I am expected to do inheritance/overrides that doesn't suffer this problem or is the fault in cssnano?是否有一种不同的方式可以让我进行不会遇到此问题的继承/覆盖,或者是 cssnano 中的错误?
Reordering CSS properties is not always a safe operation, but it is enabled in the default
preset.重新排序 CSS 属性并不总是安全的操作,但它在default
预设中是启用的。 If you encounter problems, with it, disable it.如果您遇到问题,请禁用它。 This optimisation is called cssDeclarationSorter
.这种优化称为cssDeclarationSorter
。
For example, the options to call cssnano
with:例如,调用cssnano
的选项:
{
preset: [
'default',
{ cssDeclarationSorter: false }
]
}
Or if you use cssnano
as a plugin for postcss
, this is postcss.config.js
:或者如果你使用cssnano
作为postcss
的插件,这是postcss.config.js
:
module.exports = {
plugins: {
cssnano: {
preset: [
'default',
{ cssDeclarationSorter: false }
]
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.