Joe*_*oep 48
使用ANT:
<path id="JRuby">
<fileset file="libs/jruby-complete-[VERSION].jar"/> <!-- Location of JRuby jar file -->
</path>
<target name="compileSCSS">
<echo message="Compiling scss files..." />
<property name="filesIn" value="${dir.css}/scss/**/[^_]*.scss" />
<property name="fileOutDir" value="/${dir.css}/${dir.css.build}" />
<script language="ruby" classpathref="JRuby">
<![CDATA[
require 'libs/sass-[VERSION]/lib/sass'
require 'sass/exec'
files = Dir.glob($project.getProperty('filesIn'))
Dir.mkdir($project.getProperty('fileOutDir')) unless File.exists?($project.getProperty('fileOutDir'))
files.each do
| file |
puts " [sass compiler] " + file + " -> " + $project.getProperty('fileOutDir') + "/" + File.basename(file, ".*") + ".css"
opts = Sass::Exec::Sass.new(["--load-path", File.dirname(file), file, File.join($project.getProperty('fileOutDir'), File.basename(file, ".*") + ".css")])
opts.parse
end
]]>
</script>
<echo message="Done compiling scss files!" />
</target>
Run Code Online (Sandbox Code Playgroud)
有了MAVEN:
Maven也可以这样做:使用antrun插件:
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>compileAndMinify</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<mkdir dir="${project.build.directory}/compiled" />
<echo message="Compiling scss files..."/>
<path id="JRuby">
<fileset file="${basedir}/jars/jruby-complete-[VERSION].jar"/>
</path>
<property name="filesIn" value="${project.build.directory}/css/**/[^_]*.scss" />
<property name="fileOutDir" value="${project.build.directory}/compiled/css" />
<script language="ruby" classpathref="JRuby">
<![CDATA[
require 'libs/sass-[VERSION]/lib/sass'
require 'sass/exec'
files = Dir.glob($project.getProperty('filesIn'))
Dir.mkdir($project.getProperty('fileOutDir')) unless File.exists?($project.getProperty('fileOutDir'))
files.each do
| file |
puts " [sass compiler] " + file + " -> " + $project.getProperty('fileOutDir') + "/" + File.basename(file, ".*") + ".css"
opts = Sass::Exec::Sass.new(["--load-path", File.dirname(file), file, File.join($project.getProperty('fileOutDir'), File.basename(file, ".*") + ".css")])
opts.parse
end
]]>
</script>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
Gil*_*pio 14
有一个项目:http://code.google.com/p/jsass/(但现在还处于初期阶段).
如果您对Less感兴趣,可以使用现成的Java版本:http://www.asual.com/lesscss/
小智 10
您还可以查看Web资源优化器4 J(WRO4J),它允许很多东西(缩小,资源合并)并支持更少的CSS(据我所知在运行时).
这意味着:您将wro4j过滤器添加到web.xml中,当您要求CSS时,您的.scss(或.saas)文件将编译为标准CSS.
我还没有使用它,但它似乎比这里列出的其他产品更先进.
事实上,我正在阅读Less for Java网站(http://www.asual.com/lesscss/)上的评论,WRO4J使用这个库提供"即时编译".所以我认为Less for Java是要走的路.
您是否知道Vaadin Web框架附带了自己的内置Sass编译器?请参阅https://vaadin.com/blog/-/blogs/state-of-sass-support-in-vaadin-7-today ...
我个人发现SASS语法很深,非常烦人.对于Ruby/Python人群来说,它可能是第二天性; 对我来说,作为Java人 - 不是那么多.我非常喜欢LESS,它建立在CSS语法之上,而不是想出一个新的.这有一个很好的附加优势,即能够"按原样"使用现有的CSS文件,并根据需要包含LESS功能.
也就是说,据我所知,SASS和LESS都没有java端口.两者都是基于ruby的,所以你可以在JRuby下安装它们.这种方法的唯一问题是JRuby启动时心情迟钝.但是,这并不是什么大不了的事,因为你可能会在开发中使用文件监控(一旦它启动它运行得非常顺利)并且你不会太在意你的构建在部署期间需要几秒钟的时间.
还有一些基于PHP的实现,如LessPhp,xCSS等.但是,没有亲自尝试过.
| 归档时间: |
|
| 查看次数: |
32094 次 |
| 最近记录: |