Git Product home page Git Product logo

less-sbt's Introduction

less sbt

type less css in your sbt projects

LESS Scala

a friendly css companion for coffeescripted-sbt using the less 1.4.2 embedded compiler via lesst.

settings

For sbt 0.12 users

all(for less) # compiles all less source files regardless of freshness
less # compiles less source files
charset(for less) # character encoding used in file IO (defaults to utf-8)
mini(for less) # setting for compiled minification (false by default)
colors(for less) # setting for color error output (true by default)
lessCompiler(for less) # task for resolving the less compiler to compile .less sources
filter(for less) # filter for files included by the plugin
exclude-filter(for less) # filter for files ignored by the plugin
unmanaged-sources(for less) # lists resolved less sources
clean(for less) # deletes compiled css
config:source-directory(for less) # where less files will be resolved from
config:resource-managed(for less) # where compiled css will be copied to

For sbt 0.13 users, the syntax for accessing settings keys in the REPL slightly changed. setting keys are now camel cased from the REPL and less-scoped keys can be accessed when prefiexed with less::.

install it

In your plugin definition, add

resolvers += Resolver.url(
  "bintray-sbt-plugin-releases",
    url("http://dl.bintray.com/content/sbt/sbt-plugin-releases"))(
      Resolver.ivyStylePatterns)
      
resolvers += "softprops-maven" at "http://dl.bintray.com/content/softprops/maven"

addSbtPlugin("me.lessis" % "less-sbt" % "0.2.2")

Then in your build definition, add

seq(lessSettings:_*)

This will append less-sbt's settings for the Compile and Test configurations.

To add them to other configurations, use the provided lessSettingsIn(config) method.

seq(lessSettingsIn(SomeOtherConfig):_*)

use it

Author your .less files under your project's src/main/less directory. After compiling less sources, you can find the compiled css under path/to/resource_managed/main/css

customize it

using less's built-in css minification

Less css, itself, provides a built-in minifier which you can to to shink your compiled css. To override the default mini setting, add following to your build definition after including the less settings.

(LessKeys.mini in (Compile, LessKeys.less)) := true

changing target css destination

To change the default location of compiled css files, add the following to your build definition

(resourceManaged in (Compile, LessKeys.less)) <<= (crossTarget in Compile)(_ / "your_preference" / "css")

working with @imports

Some lesscss projects, like Twitter's Bootstrap project contain one main .less file which imports multiple .less files using the @import feature of lesscss. To achieve the same style of compilation with less-sbt, set the filter defined by less-sbt to the target of compilation.

(LessKeys.filter in (Compile, LessKeys.less)) := "your_main.less"

This will build a single your_main.css file which includes all of the @imported style definitions.

To see an example of compiling Bootstrap itself, check out the scripted bootstrap test.

You will find all custom less-sbt keys within the LessKeys module.

issues

Have an issue? Tell me about it

contributions

I'll take them where they make sense. Please use a feature branch in your fork, i.e. git checkout -b my-cool-feature, and if possible, write a scripted test for it.

Doug Tangren (softprops) 2011-2013

less-sbt's People

Contributors

jrudolph avatar kastigar avatar melezov avatar softprops avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

less-sbt's Issues

Minifier doesn't work

Hi,

I encountered a problem with the less minifier.

I set (LessKeys.mini in (Compile, LessKeys.less)) := true
in my build definition (after including the lessSettings).

When I type less::mini into SBT-console, it get the result [info] true

But yet the compiled CSS isn't minified at all.
Apparently there is no difference in the compile CSS, whether mini is true or false.

How is the minifier supposed to work?

I'm using sbt.version = 0.13.0 and less-sbt 0.2.1

Cheers,
Max.

Imports should not be compiled

Great plugin... but I'm having trouble with imports.

I have two files thus:

baseline.less
forms.less

Baseline declares a variable @baseline and imports forms with @import "forms.less";

less-sbt compiles baseline.less just fine.

But then immediately afterwards, less-sbt tries to compile forms.less which has no reference to @baseline and it tanks.

Lift/compile:less: error occured while compiling /less/forms.less: variable @baseline is undefined

I tried moving the imports to another dir and rereferencing, but then baseline won't compile. Is there a way to exclude compilation of imports?

A great project to try this on is twitter bootstrap.

Thanks!

"[info] No less files to compile" spam

This output appears a lot.

> compile
[info] No less files to compile
[info] No less files to compile
[success] Total time: 0 s, completed Nov 9, 2011 3:52:13 PM
> less
[info] Compiling 1 less files to /.../webapp/css
[success] Total time: 1 s, completed Nov 9, 2011 3:52:17 PM

The above output is interesting because less-sbt is stating that there are no less files to compile while doing a compile task. But compiling isn't compiling less files at the moment (though it would be nice if it did). However, when I then type in the less task you can see that there were less files to compile.

Thanks for this and the coffeescripted-sbt plugins by the way!

CSS output file contains just 'null'

Im trying to use the latest version of the plugin and after compiling css i just get under resource_managed/main/css a .css file with output 'null'.

Compile Error: Method "doctest" not found in "org.mozilla.javascript.tools.shell.Global"

I set up less-sbt with the minimal configurations and I keep getting this compile error:

compile:less: Error occured while compiling C:...\src\main\less\main.less: Method "doctest" not found in "org.mozilla.javascript.tools.shell.Global". (compiler.scala#39)

What I did was add this to my build.sbt:

seq(lessSettings:_*)

and added this to project/plugins.sbt:

addSbtPlugin("me.lessis" % "less-sbt" % "0.1.10")

resolvers += Resolver.url("sbt-plugin-releases",
new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(
Resolver.ivyStylePatterns)

I also tried 0.1.9 with no avail.

The only thing in the less folder is the main.less file, which just had this:

@color: #4D926F;

header {

color: @color;
}

I also tried making main.less into an empty file, with no avail :(

Regular and minified output

It doesn't look like it from my investigating, but I just wanted to make sure. There isn't a way to have this output both a regular css and minified css file is there? And if not, is this something you would consider putting in?
Thanks for your time, consideration, and plugin!

Compiled JS artifacts not available anymore in 0.1.6

Doug,

I have a strange issue that is preventing me from upgrading from 0.1.5 to 0.1.6:

I run less-sbt with only one custom setting:

// have less-sbt compiled templates merged right in with our other resources
resourceManaged in (Compile, LessKeys.less) <<= resourceManaged in Compile

With 0.1.5 my JS artifacts all eventually land in target/scala-2.9.1/classes were my application expects them. With 0.1.6 however they stay in target/scala-2.9.1/resource_managed and don't get copied over to .../classes.

What has changed between these versions to cause this difference in behavior?
How can achieve the previous behavior with 0.1.6?

Cheers,
Mathias

Multiple root sources

Hi!

We have one root less source for internal part of the site and other one for public part.
With LessKeys.filter as I understand it is possible to list only one file.

Is it possible to compile multiple root sources?

factor out compiler wrapper

Some times I wanna use less outside the context of and sbt project. This could be conscripted but the sbt specfic deps need factored out.

Unicode symbols

Hello. I am using less-sbt version 0.1.10.

In such less file (UTF-8) i use:

cite{
     font-style: italic;
     float: right;
     font-size: 11px;
     &:before{
          content: "";
     }
}

I used unicode EM DASH http://www.fileformat.info/info/unicode/char/2013/index.htm
As a result i got such css (also in UTF-8):

cite:before{content:"вАФ ";}

In my boot only this about less plugin:

(LessKeys.mini in (Compile, LessKeys.less)) := true

(excludeFilter in (Compile, LessKeys.less)) := "_*"

filter and excludeFilter are not used

When executing "less", the filter and excludeFilter settings are never used. I want to do something like this:

lazy val lessSettings = LessPlugin.lessSettings ++ Seq(
  LessKeys.filter in (Compile, LessKeys.less) := ("*.less" - "*.lib.less"))

But also all files with *.lib.less are include when executing "less".

"print" is not defined

Hi!

Since today i can't do less task. I get such error:

[info] Compiling 1 less sources to /home/kastigar/.../target/scala-2.9.1/resource_managed/main/css
[error] {file:/home/kastigar/.../}default-bbdc92/compile:less: error occured while compiling /home/kastigar/.../src/main/less/main.less: ReferenceError: "print" is not defined. (less-rhino-1.1.3.js#2420)

I don't know what was changed (i don't remember when i have last recompilation of my less files).

Modifying resourceManaged doesn't appear to impact the plugin

I'm trying to change where the css files are compiled to in my build.sbt file. For the CoffeeScriptedSbt plugin I can do this with a line like:

(targetDirectory in Coffee) <<= (crossTarget in Compile)(t => t / "webapp_managed" / "js")

This works fine.

With less-sbt I appear to have to write:

(targetDirectory in LessKeys.less) <<= (crossTarget in Compile)(t => t / "webapp_managed" / "css")

whilst this seems to change the setting, in that target-directory(for less) from the sbt prompt gives the right result, the less command nevertheless appears to compile to the same place as it did before.

On the other hand, I find configuration in sbt to be a process of trail and error so I could be doing completely the wrong thing here.

Compile error when updating to Bootstrap 2.3.2

When updating bootstrap to 2.3.2 I get a compile error in sbt. The cause of the error is the mixins.less file from Bootstrap 2.3.2, that contains a new code structure which I think cannot be compiled by the current LESS compiler in less-sbt. The root cause of the compiler error is the following commit/change in bootstrap:

twbs/bootstrap@6b9bb54

Here a demo project that reproduces the problem and documents the error I get.

https://github.com/rudolfb/test_bootstrap_2.3.2_compile_error
https://github.com/rudolfb/test_bootstrap_2.3.2_compile_error.git

I hope you are the correct person to post this issue to. Please feel free to ask should you have any questions.

F.Y.I: I am new to scala, lift, less, sbt et al. If this does not have anything to do with less-sbt I would appreciate if you could tell me whom to contact to have this looked at. It might even be an error on my side in my project that I am not capable to see yet.

Regards

Rudolf

Error messages are less than ideal

One example:

error evaluating function `darken`

less-sbt could show the values of the properties filename, line, column, and extract from the javascript exception for a little more context.

I don't blame it on less-sbt, not at all. Looking at the less issue tracker it seems that less has soooo many unsolved problems. Than looking at the less code it seems they just don't have any proper error reporting in situations like this. Then looking at rhino it seems they don't even manage to put apidocs on the web. Oh yes.

Problems using with xsbt-web-plugin…

This is not at all an issue, but rather a question - couldn't find a more proper place to ask…? I'm a maven guy and kind of new to sbt so please bare with me if my question is obvious.

So, I would like to have my .less files live under /src/main/less and then be compiled to .css under some "generated" output - definitely not under src/main/webapp. I would then have this built into my war at the correct place as well as served by an embedded jetty using xsbt-webapp-plugin. What I have is the following:

seq(lessSettings:_*)

// Only main file (imports the others)
(LessKeys.filter in (Compile, LessKeys.less)) := "bootstrap.less"

// minify
(LessKeys.mini in (Compile, LessKeys.less)) := true

webappResources in Compile <+= (crossTarget in Compile)(_ / "resource_managed" / "main")

So the last line here I added to make xsbt-web-plugin bake the compiled css into the webapp. However, I see 2 problems with this:

  1. I will expose other stuff under resource_managed like generated sources, right? Say, scalaxb might put generated scala-sources there too? I can't figure out how to add conditionally and still preserve paths (like "/css" ). If I do
webappResources in Compile <+= (crossTarget in Compile)(_ / "resource_managed" / "main" / "css")

my css is put straight under context root and I want /css/bootstrap.css for example.

  1. The css is still unnescessarily in the classpath of the webapp too:
~/temp/ $ tar -tf example.war | grep css
WEB-INF/classes/css/
css/
css/bootstrap.css
WEB-INF/classes/css/bootstrap.css

Are there any easy ways to achieve what I want? I figured this was the place to ask even though I guess the answer might be in settings of the web-plugin.

Thanks,
Viktor

Not working for Bootstrap 3.0 ?

I haven't looked to heavily into this, but when I try to compile only the bootstrap sources (via "bootstrap.less") using the filter as described, the resulting main.css file is empty. Wondering if there is something specific about the latest version of Bootstrap that isn't being handled correctly (maybe imports?).

performance enhancement

use one instance of the compiler per sbt session. ala the recent change contributed in the coffeescripted plugin

Problem with nested relative imports

Hi!

There is such file structure:
less/
|-lib/
| |-- lib.less
| |-- sub.less
| -- main.less

main.less:

@import "lib/lib.less"

lib/lib.less:

@import "sub.less"

This doesn't work. Somehow while importing sub.less in lib.less it searches for sub.less instead of lib/sub.less. Browser version of lesscss works fine.

lesst dependency not available

Heya, Doug.

You should nudge your constituents to add the bintray resolver to their builds. I'm worried lest they would not be able to resolve lesst otherwise. Unlesst you mean to publish lesst on a central repository.

resolvers += "softprops-maven" at "http://dl.bintray.com/content/softprops/maven"

Regards,
Marko

compile task not recompiling less files

It would be useful if the "compile" would recompile less instead of having to do a separate "less" task. This way one can do "~compile" while doing development to get continuous compilation regardless of whether one is editing .less files or .host-language files.

Changing an imported less file does not recompile the parent

If you change a less file the plugin correctly recompiles it, but if another less file imports it then that file also needs to be recompiled to include the changes in the file it imports.

I'll guess that dependency checking might be hard but possibly there could be an option added to compile all less files when one file changes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.