首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让gulp-clean-css保留之前的空格!重要吗?

如何让gulp-clean-css保留之前的空格!重要吗?
EN

Stack Overflow用户
提问于 2019-08-26 11:49:43
回答 1查看 249关注 0票数 1

在优化代码时,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 () {},但它不起作用。

代码语言:javascript
复制
.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 */包围代码的关键部分,但我正在寻找更好的方法。

EN

回答 1

Stack Overflow用户

发布于 2019-08-27 22:47:30

嗯,看起来吞咽-替换插件有帮助了:

来自gulpfile.js:

const replace =require(‘gulp replace’)

..。停..。和:.pipe(replace('!important',‘!important'))

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57651540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档