Java的SASS实现?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1751479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 22:17:56  来源:igfitidea点击:

SASS implementation for Java?

javamavenantjrubysass

提问by user213225

I'm looking for SASS implementation in Java (could be used with JSP/JSF). For Python I've found CleverCSS, but there is nothing for Java. Anyone heard something about this sort of tool for generating CSS?

我正在寻找 Java 中的 SASS 实现(可以与 JSP/JSF 一起使用)。对于 Python,我找到了 CleverCSS,但对于 Java 却没有。有人听说过这种用于生成 CSS 的工具吗?

回答by ChssPly76

I personally find SASS syntax deeply, horribly annoying. For Ruby / Python crowd it may come as second nature; for me as Java guy - not so much. I stronglyprefer LESSwhich builds upon CSS syntax instead of coming up with a new one. That has a nice added advantage of being able to use your existing CSS files "as is" and incorporate LESS features as needed.

我个人觉得 SASS 语法很深,非常烦人。对于 Ruby / Python 人群来说,这可能是第二天性;对我作为 Java 人来说 - 不是那么多。我非常喜欢LESS,它建立在 CSS 语法之上,而不是提出新的语法。这有一个很好的附加优势,即能够“按原样”使用现有的 CSS 文件并根据需要合并 LESS 功能。

That said, neither SASS nor LESS have java ports as far as I know. Both are ruby-based, however, so you can install them under JRuby. The only issue with that approach is JRuby is mind-numbingly slow to start up. It's not a huge deal, though, because you're likely going to use file monitoring in development (and once it does startup it runs very smooth) and you're not going to care as much that your build takes few seconds longer during deployment.

也就是说,据我所知,SASS 和 LESS 都没有 Java 端口。然而,两者都是基于 ruby​​ 的,因此您可以将它们安装在JRuby下。这种方法的唯一问题是 JRuby 启动速度慢得让人麻木。不过,这不是什么大问题,因为您可能会在开发中使用文件监控(并且一旦启动,它就会运行得非常顺畅)并且您不会太在意您的构建在部署期间需要多花几秒钟的时间.

There are also some PHP-based implementations like LessPhp, xCSSand others. Haven't tried them personally, though.

还有一些基于 PHP 的实现,如LessPhpxCSS等。不过还没有亲自尝试过。

回答by aussiegeek

Given that SASS has to be converted to CSS to be usable, what is wrong with using sass2css that distributes with Ruby SASS?

鉴于必须将 SASS 转换为 CSS 才能使用,使用与 Ruby SASS 一起分发的 sass2css 有什么问题?

回答by Gilberto Olimpio

There is one project: http://code.google.com/p/jsass/(but it's in a very early stage).

有一个项目:http: //code.google.com/p/jsass/(但它处于非常早期的阶段)。

If you are interested in Less, there is a ready-to-use Java version for it: http://www.asual.com/lesscss/

如果你对 Less 感兴趣,这里有一个现成的 Java 版本:http: //www.asual.com/lesscss/

回答by legzo

You can also take a look to Web Resource Optimizer 4 J (WRO4J)which allows a lots a things (minification, resource merging) and supports Less CSS (at runtime as far as I know).

您还可以查看Web Resource Optimizer 4 J (WRO4J),它允许做很多事情(缩小、资源合并)并支持 Less CSS(据我所知,在运行时)。

This means: you add wro4j filter to your web.xml and when you ask for a CSS, your .scss (or .saas) files are compiled to standard CSS.

这意味着:您将 wro4j 过滤器添加到您的 web.xml 并且当您请求 CSS 时,您的 .scss(或 .saas)文件将被编译为标准 CSS。

I have not used it yet, but it seems more advanced than other products listed here.

我还没有使用它,但它似乎比这里列出的其他产品更先进。



In fact, I was reading comments on the Less for Java website (http://www.asual.com/lesscss/) and WRO4J uses this library to provide it's "on the fly Less compilation". So I think Less for Java is the way to go.

事实上,我正在阅读 Less for Java 网站 ( http://www.asual.com/lesscss/)上的评论,WRO4J 使用这个库来提供它的“动态 Less 编译”。所以我认为 Java 的 Less 是要走的路。

回答by Joep

With ANT:

使用蚂蚁:

  1. Download JRuby complete jar file (JRuby Complete jar download page)
  2. Download the latest HAML/SASS code (HAML/SASS tarball), and extract it. Put it in "/libs/sass-[VERSION]"
  3. Add the following to an ant build file.
  4. Replace [VERSION] in the script to the corresponding versions of JRuby and SASS
  5. Run the ant script, and the sass or scss files will be compiled!
  1. 下载 JRuby 完整 jar 文件(JRuby 完整 jar 下载页面
  2. 下载最新的 HAML/SASS 代码 ( HAML/SASS tarball),并解压。把它放在“/libs/sass-[VERSION]”中
  3. 将以下内容添加到 ant 构建文件中。
  4. 将脚本中的 [VERSION] 替换为 JRuby 和 SASS 的对应版本
  5. 运行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>

With MAVEN:

使用 MAVEN:

Maven can also do this: Using the antrun plugin:

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>  

回答by Darrin Holst

You can try this filter I just put together - https://github.com/darrinholst/sass-java

你可以试试这个我刚刚放在一起的过滤器 - https://github.com/darrinholst/sass-java

回答by spaaarky21

I know I'm late to the party, but this is the approach I took to using SASS in a Java project with an Ant build: http://workingonthecoolstuff.blogspot.com/2011/02/using-sass-in-ant-build.htmlTo summarize, I'm doing the build on a machine with Ruby and Sass installed so it was as easy as calling the sass command/application using the Ant "apply" task with a fileset that includes all the SCSS/SASS files.

我知道我迟到了,但这是我在带有 Ant 构建的 Java 项目中使用 SASS 的方法:http: //workingonthecoolstuff.blogspot.com/2011/02/using-sass-in-ant -build.html总而言之,我在一台安装了 Ruby 和 Sass 的机器上进行构建,所以它就像使用 Ant“apply”任务调用 sass 命令/应用程序一样简单,文件集包含所有 SCSS/SASS文件。

回答by Eric H

I am using Compass & Sass in my eclipse project using Ant.

我在使用 Ant 的 Eclipse 项目中使用 Compass & Sass。

I followed this tutorial here:

我在这里遵循了本教程:

http://caueguerra.com/tutorial-using-sass-in-a-java-project

http://caueguerra.com/tutorial-using-sass-in-a-java-project

Compass extends Sass and allows for my other extras.

Compass 扩展了 Sass 并允许我的其他附加功能。

http://compass-style.org/

http://compass-style.org/

回答by Tom Yeh

ZUSSis a good alternative to LESS and SASS. It is similar to LESS. Unlike LESS and SASS, the processing of the ZUSS files doesn't require the JavaScript interpreter.

ZUSS是 LESS 和 SASS 的一个很好的替代品。它类似于 LESS。与 LESS 和 SASS 不同,ZUSS 文件的处理不需要 JavaScript 解释器。

Disclaimer: I am the developer of ZUSS. I developed it simply because I can't find a neat solution for Java.

免责声明:我是 ZUSS 的开发者。我开发它只是因为我找不到适用于 Java 的简洁解决方案。

回答by Eran Medan

It seems there is one after all (developed probably a while after this question was asked)

似乎毕竟有一个(可能是在提出这个问题后一段时间开发的)

https://github.com/Jasig/sass-maven-plugin

https://github.com/Jasig/sass-maven-plugin