NOTE: This project is no longer maintained. You might want to look at sbt-web which has a closure complier.
If you have not already added the sbt community plugin resolver to your plugin definition file, add this
resolvers += Resolver.url("sbt-plugin-releases", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))( Resolver.ivyStylePatterns)
Then add this (see ls.implicit.ly for current version)
addSbtPlugin("org.scala-sbt" % "sbt-closure" % "0.1.0")
Then in your build definition, add
This will append
sbt-closure's settings for the
To add them to other configurations, use the provided
The plugin scans your
and looks for files of extension
.jsm. These files
# You can specify remote files using URLs... http://code.jquery.com/jquery-1.5.1.js # ...and local files using regular paths # (relative to the location of the manifest): lib/foo.js bar.js ../bar.js # Blank lines and bash-style comments are ignored.
The plugin compiles this in two phases: first, it downloads and caches any
remote scripts. Second, it feeds all of the specified scripts into the Closure
compiler. The compiler outputs a file with the same name but with a
.js extension under
For example, if your manifest
file is at
path would be
resource_managed/main/js/foo.js in the target tree.
If, on compilation, the plugin finds remote scripts already cached on your
filesystem, it won't try to download them again. Running
sbt clean will
delete the cache.
The plugin is tied to the compile task and will run whenver compile is run. You can
closure to run it on its own.
clean(for closure) will delete the generated files.
If you're using xsbt-web-plugin, add the output files to the webapp with:
// add managed resources to the webapp (webappResources in Compile) <+= (resourceManaged in Compile)
Changing the directory that is scanned, use:
(sourceDirectory in (Compile, ClosureKeys.closure)) <<= (sourceDirectory in Compile)(_ / "path" / "to" / "jsmfiles")
Changing target js destination:
To change the default location of compiled js files, add the following to your build definition
(resourceManaged in (Compile, ClosureKeys.closure)) <<= (resourceManaged in Compile)(_ / "your_preference" / "js")
(ClosureKeys.suffix in (Compile, ClosureKeys.closure)) := "4"
Then if you have manifest file
This is only half of the puzzle, though. In order to know what that suffix is in your code, you can use the sbt-buildinfo plugin. Add the plugin to your project, then add the following to your build.sbt:
seq(buildInfoSettings: _*) buildInfoPackage := "mypackage" buildInfoKeys := Seq[Scoped](ClosureKeys.suffix in (Compile, ClosureKeys.closure)) sourceGenerators in Compile <+= buildInfo
This will generate a Scala file with your suffix in
you can access it in your code like this:
In my Lift project I have the following snippet:
Which is called in my template like:
This plugin is a sbt 0.11.2 port of sbt-closure
It was modeled after and heavily influenced by less-sbt