我正在寻找 Java 中的 SASS 实现(可以与 JSP/JSF 一起使用)。对于 Python,我找到了 CleverCSS,但对于 Java 则没有。有人听说过这种用于生成 CSS 的工具吗?
最佳答案
使用 ANT:
- 下载JRuby完整的jar文件(JRuby Complete jar download page)
- 下载最新的 HAML/SASS 代码 (HAML/SASS tarball),并解压。放入“/libs/sass-[VERSION]”
- 将以下内容添加到 ant 构建文件中。
- 将脚本中的[VERSION]替换为JRuby和SASS的对应版本
- 运行ant脚本,编译sass或scss文件!
<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>
使用 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>
关于java - Java的SASS实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1751479/