Programing

Java 용 SASS 구현?

lottogame 2020. 10. 22. 07:36
반응형

Java 용 SASS 구현?


Java에서 SASS 구현을 찾고 있습니다 (JSP / JSF와 함께 사용할 수 있음). Python의 경우 CleverCSS를 찾았지만 Java에는 아무것도 없습니다. CSS 생성을위한 이런 종류의 도구에 대해 들어 본 사람이 있습니까?


ANT 사용 :

  1. JRuby 완전한 jar 파일 다운로드 ( JRuby Complete 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>

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>  

ZUSS is 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.

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


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

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


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).

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.

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.


Did you know that the Vaadin web framework comes with it's own built-in Sass compiler? See https://vaadin.com/blog/-/blogs/state-of-sass-support-in-vaadin-7-today ...


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 strongly prefer LESS which 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.

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.

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


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

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


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


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


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

I followed this tutorial here:

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

Compass extends Sass and allows for my other extras.

http://compass-style.org/


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.html To 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.


Sassc is a command-line implementation in C, which should be easy to add to the build process. Based on the authors I'd say it should stay up to date with sass:

Sass was originally created by the co-creator of this library, Hampton Catlin (@hcatlin). The extension and continuing evolution of the language has all been the result of years of work by Nathan Weizenbaum (@nex3) and Chris Eppstein (@chriseppstein).

참고URL : https://stackoverflow.com/questions/1751479/sass-implementation-for-java

반응형