1

我有一个带有可变部分的 css 文件,我想在运行构建脚本时从文件中删除它(但我需要将该部分保留在源代码中)。我想我会用某种标记将该部分包装在评论(/ * remove-front / & / remove-back */)中,然后使用ant将评论之间的所有内容都替换掉。

这是我的例子:

/* remove-front */
.footerGradients {
  /* gradient settings (used http://www.colorzilla.com/gradient-editor/ to generate following code) */

  background-color: #606869;
  background: -webkit-gradient(linear, left bottom, left top, color-stop(0, #2f3838), color-stop(100%, #606869));
  background: -moz-linear-gradient(center bottom, #2f3838 0, #606869 100%);
  background: -ms-linear-gradient(center bottom, #2f3838 0, #606869 100%);
  background: -o-linear-gradient(center bottom, #2f3838 0, #606869 100%);
  background: linear-gradient(center bottom, #2f3838 0, #606869 100%);
  -pie-background: linear-gradient(#2f3838, #606869);
  filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#2f3838,endColorstr=#606869);
  /* end gradient settings */

}
.footerShadows {
  /* box shadow settings (used http://css3generator.com/ to generate following code) */

  -webkit-box-shadow: 0 0 2px 0 #293535;
  -moz-box-shadow: 0 0 2px 0 #293535;
  box-shadow: 0 0 2px 0 #293535;
  /* end box shadow settings */

}
/* remove-back */

提前感谢您的回复。

4

2 回答 2

1

我和@FailedDev 有同样的想法,但是在尝试我的 Eclipse 时,它​​对“m”选项犹豫不决(并且我添加了使用/*remove-front */(空格)和/*REMOVE-BACK*/(不区分大小写)的能力:

<copy tofile="src/test2.css" file="src/test.css" overwrite="true"/>
<replaceregexp 
   file="src/test2.css" 
   match="/\*\s*remove-front\s*\*/.*?/\*\s*remove-back\s*\*/"
   replace=""
   flags="gsi" 
   byline="false"/>
于 2011-10-05T23:28:47.377 回答
0

我会使用标准的 replaceregexp 任务:

http://ant.apache.org/manual/Tasks/replaceregexp.html

 <replaceregexp file="${css.file}"
                match="/\* remove-front \*/.*?/\* remove-back \*/"
                replace=""
                byline="false"
                flags="gs"
/>
于 2011-10-05T23:20:53.423 回答