在优化代码时,gulp-clean-css会删除CSS值和结束的!important单词之间的重要空格,例如。width: 600px !important成为width: 600px!important
顺便说一句,level 1 semicolonAfterLastProperty: true设置也不起作用!
我已经阅读了这里的文档- https://github.com/jakubpawlowicz/clean-css#formatting-options -并尝试使用level1 transform: function () {},但它不起作用。
.pipe(cleanCSS({
format : 'beautify',
level: {
1: {
transform: function (propertyName, propertyValue, selector ) {
if (propertyValue.indexOf('!important') > -1) {
return propertyValue.replace('!important', ' !important');
}
},
semicolonAfterLastProperty: true
},
2 : {
removeDuplicateRules : true
}
}
}))到目前为止,唯一有效的解决方案是用/* clean-css ignore:start */ .... /* clean-css ignore: end */包围代码的关键部分,但我正在寻找更好的方法。
发布于 2019-08-27 22:47:30
嗯,看起来吞咽-替换插件有帮助了:
来自gulpfile.js:
const replace =require(‘gulp replace’)
..。停..。和:.pipe(replace('!important',‘!important'))
https://stackoverflow.com/questions/57651540
复制相似问题