eriwen/gradle-js-plugin — pull request #53 by joefitzgerald (2013-02-08 22:46:12+00:00)
Title: RequireJS Optimizer Support

Here's an initial cut at adding r.js optimizer (http://requirejs.org/docs/optimization.html) support.

I have included some unit tests to validate the task works. I've also used this in another Gradle project to do the work that Backbone Boilerplate's RequireJS Grunt task (https://github.com/backbone-boilerplate/grunt-bbb) would normally do, and it produces the desired output.

* task.source is used to determine whether or not the task execution is up to date
* task.dest is used to specify the output file
* Rhino's execution output is echoed to stdout
* The task leverages the existing JavaScriptSourceSet in the plugin
* requirejs.buildprofile is used to specify a build profile script (http://requirejs.org/docs/optimization.html#basics)
* requirejs.options is used to specify additional options, which take precedence over options in the build profile (http://requirejs.org/docs/optimization.html#options)

### Example

apply plugin: 'js'

// Optionally, use a build profile
// requirejs.buildprofile = file("build.js")
requirejs.options = [
mainConfigFile: "app/config.js",
optimize: "none",
logLevel: 2,
skipModuleInsertion: false,
name: "config",
wrap: false,
]

javascript
{
source {
dev {
js {
srcDir 'app'
include "**/*.js"
exclude "**/*.min.js"
}
}
prod {
js {
srcDir 'app'
include "**/*.min.js"
}
}
}
}

task runrequirejs(type: com.eriwen.gradle.js.tasks.RequireJsTask) {
source = javascript.source.dev.js.files
dest = file("$buildDir/require.js")
}