Skip to content

SASS compiler for Clj, Lein and Boot, using Libsass Java wrapper

Notifications You must be signed in to change notification settings

Deraen/sass4clj

Repository files navigation

Sass4clj

Clojars Project Build Status AppVeyor

Clojure wrapper forjsassJNA wrapper for Libsass. This repository also containsBootandLeiningentasks.

For parallel Less library checkless4clj

ATTENTION:libsass(the C library) and the JNA wrapper libraryjsassare deprecated. Consider usingDart Sassif you do not need to read SCSS files from the Java classpath.You can integrate Dart Sass process with Shadow CLJS.

Both sass4clj still works and will receive bug fixes, but the difference between libsass and dart-sass will continue growing.

Some ideas if you need to read files from the classpath or jar files:

  • It might be possible to extend dart-sass throughImporter API
  • Extract files from the jar files in a script before calling dart-sass compile (for example, usingcljandunzip)

Features

  • Jsass features
    • Requires Java 1.8
    • Linux & Windows builds are automatically tested
    • (Doesn't work on Alpine based Docker images)
  • Load imports directly from Java classpath (e.g. Webjars)
    • Add dependency[org.webjars.bower/bootstrap "4.0.0-alpha" ]to useBootstrap
  • Assumes that files starting with_arepartial filesand should not be compiled into CSS files.
  • Non feature: compilation warnings are reported by libsass/jsass directly to stdout, and aren't accessible from sass4clj API.

BootClojars Project

  • Provides thesasstask (deraen.boot-sass/sass)
  • Select main files usinginputsoption
  • or, for each.sassor.scssfile not starting with_in the fileset creates equivalent.cssfile.
  • Checkboot sass --helpfor task options.

LeiningenClojars Project

  • Provides thesass4cljtask
  • Select main files usinginputsoption
  • or, for each.sassor.scssfile not starting with_in source-dirs creates equivalent.cssfile.
  • Checklein help sass4cljfor options.

Clj

Test in the repository:

clj -m sass4clj.main --source-paths test-resources

Checkclj -m sass4clj.main --helpfor options.

Import load order

Loading order for@import "{name}";on file at{path}

  1. Local file at{path}/{name}.sassor{path}/{name}.scss
  2. Local files on other source-paths,{source-path}/{name}.ext
  3. Classpath resource(io/resource "{name}.ext" )
  4. Classpath resource(io/resource "{path}/{name}.ext" )
  5. Webjar asset
    • ResourceMETA-INF/resources/webjars/{package}/{version}/{path}can be referred using{package}/{path}
    • For example@import "bootstrap/scss/bootstrap.scss";will importMETA-INF/resources/webjars/bootstrap/4.0.0-alpha/scss/bootstrap.scss

FAQ

Shadow-cljs integration

If you want to combine CLJS compilation with Shadow CLJS and Sass compilation, you can create your function which starts both watches and run this using shadow-cljsclj-run task.

(nsapp.shadow
(:require[shadow.cljs.devtools.api:asshadow]
[sass4clj.api:assass]
[clojure.edn:asedn]))

(defnwatch
{:shadow/requires-servertrue}
[& _args]
;;Sass compilation probably starts faster.
;;Both watches keep running until ctrl-c.
(sass/start(->(edn/read-string(slurp"sass4clj.edn"))
(assoc:target-path"target/dev/public/css")))
(shadow/watch:app))

The configuration file, sass4clj.edn, is also supported by sass4clj.main namespace. You could use that to compile CSS for your production build instead of the leiningen plugin.

And start the watch with (or with whatever tool you are using):

lein run -m shadow.cljs.devtools.cli clj-run app.shadow/watch

You need to ensure that the classpath used by shadow-cljs containsderaen/sass4clj and any packages where you are importing sass files from.

Log configuration

If you don't have any slf4j implementations, you will see a warning:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

To disable this, add a no operation logger to your project. As this is only required on the build phase, you can use:scope "test"so that the dependency is not transitive and is not included in Uberjar. Alternatively, you can add this dependency to your Leiningen dev profile.

[org.slf4j/slf4j-nop "1.7.13":scope "test" ]

License

Copyright © 2014-2021 Juho Teperi

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

SASS compiler for Clj, Lein and Boot, using Libsass Java wrapper

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages