Gradle plugin for working with JS
Switch branches/tags
Nothing to show
Pull request Compare This branch is 242 commits behind eriwen:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
gradle/wrapper
src
.gitignore
LICENSE
README.md
build.gradle
gradlew
gradlew.bat
plugin.gradle

README.md

Gradle Javascript Plugin!

Aiming to be the simplest way to manage your Javascript in a build.

Quick Start

Wrangling your JS in a Gradle build is easy! Just add this to your build.gradle file:

    // Pull the plugin from a Maven Repo
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.eriwen:gradle-js-plugin:0.2'
        }
    }
    // Invoke the plugin
    apply plugin: 'js'

    // Specify a collection of files to be combined, then minified and finally GZip compressed.
    js {
        inputs.files fileTree(dir: "${projectDir}/js", include: "**/*.js")
        outputs.file file("${buildDir}/combinedMinifiedAndGzipped.js")
    }

Need more than 1 set of files generated? Just add another js block:

    js {
        inputs.files fileTree(dir: "${projectDir}/otherdir", includes: ["file1.js", "file2.js"])
        outputs.file file("${buildDir}/teenytiny.js")
    }

What if I want my JS files combined in a certain order? This is how you do it (kludgy) for now, but we're working on a more elegant solution (see progress on Issue #4):

    js {
        file2 = fileTree(dir: "${projectDir}/js", includes: ['file2.js'])
        file1 = fileTree(dir: "${projectDir}/js", includes: ['file1.js'])
        inputs.files file2 + file1
        outputs.file file("${buildDir}/all.js")
    }

Want more fine-grained control or just want to combine, minify or zip your files?

    // Combine JS files
    combineJs {
        inputs.files fileTree(dir: "${projectDir}/js", include: "**/*.js")
        outputs.file file("${buildDir}/all.js")
    }
    
    // Minify with Google Closure Compiler
    minifyJs {
        inputs.file file("${buildDir}/all.js")
        outputs.file file("${buildDir}/all-min.js")
        warningLevel = 'QUIET'
    }
    
    // GZip it!
    gzipJs {
        inputs.file file("${buildDir}/all-min.js")
        outputs.file input
    }

JSHint support

    jshint {
	    inputs.files files('js/main.js')
	    outputs.file file("${buildDir}/jshint.out")
    }

Available Tasks and Options

combineJs

  • input.files FileCollection of files to merge
  • output.file File for combined output

minifyJs (Uses the Google Closure Compiler)

  • input.file File to minify
  • output.file File for minified output
  • (Optional) compilationLevel = 'WHITESPACE_ONLY', 'SIMPLE_OPTIMIZATIONS' (default), or 'ADVANCED_OPTIMIZATIONS' (are you hardcore?)
  • (Optional) warningLevel = 'QUIET', 'DEFAULT' (default), or 'VERBOSE'
  • (Optional) options = CompilerOptions object

gzipJs

  • input.file File to compress
  • output.file File for compressed output

js

  • input.files Files to combine, minify and gzip
  • output.file File for tiny output :)
  • (Optional) compilationLevel = 'WHITESPACE_ONLY', 'SIMPLE_OPTIMIZATIONS' (default), or 'ADVANCED_OPTIMIZATIONS' (are you hardcore?)
  • (Optional) warningLevel = 'QUIET', 'DEFAULT' (default), or 'VERBOSE'
  • (Optional) options = CompilerOptions object

jshint

  • input.files Files to assess with JSHint
  • output.file File for report output

What, you want more? Tell me then!

See Also

The Gradle CSS Plugin!