-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for WebJars and LESS assets pipeline
Signed-off-by: Ashar Fuadi <[email protected]>
- Loading branch information
Showing
36 changed files
with
1,273 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
=== Adding asset pipelines | ||
|
||
The Play plugin's `createPlayAssetsJar` task (on which `runPlay` and `dist` tasks depend) bundles all assets into a single jar file. This jar file is included in the distribution package to be served by the Play application. | ||
|
||
The following asset pipelines are supported. | ||
|
||
==== Public assets | ||
|
||
Files in the `public/` directory will be included in the assets JAR without any processing. | ||
|
||
==== JavaScript minification | ||
|
||
Files in the `javaScript` source set (the default one is `app/assets` with `\**/*.js` filter), will be minified using Google Closure compiler and then included in the assets jar. | ||
|
||
==== WebJars | ||
|
||
WebJar libraries will be extracted and then included in the assets jar, under the `lib/` subdirectory. | ||
|
||
To apply this pipeline, apply the `org.gradle.playframework-webjars` plugin as well: | ||
|
||
[source,groovy] | ||
.build.gradle | ||
---- | ||
plugins { | ||
id 'org.gradle.playframework' version '0.9' | ||
id 'org.gradle.playframework-webjars' version '0.9' | ||
} | ||
---- | ||
|
||
To add a WebJar library, add it to the dependency list using `webJar` configuration, e.g.: | ||
|
||
[source,groovy] | ||
.build.gradle | ||
---- | ||
dependencies { | ||
webJar 'org.webjars:requirejs:2.3.6' | ||
} | ||
---- | ||
|
||
==== LESS compilation | ||
|
||
Files in the `less` source set (the default one is `app/assets` with `\**/*.less` filter) will be compiled into CSS and then included in the assets jar. | ||
|
||
To apply this pipeline, apply the `org.gradle.playframework-less` plugin as well: | ||
|
||
[source,groovy] | ||
.build.gradle | ||
---- | ||
plugins { | ||
id 'org.gradle.playframework' version '0.9' | ||
id 'org.gradle.playframework-less' version '0.9' | ||
} | ||
---- | ||
|
||
The following `\@import`s in LESS files are supported: | ||
|
||
- Partial LESS files (ones with start with underscores, such ass `_common.less`). | ||
- WebJar extracted files (using the WebJar pipeline described above), with `lib/` subdirectory prefix. | ||
|
||
Example: | ||
|
||
[source,less] | ||
.main.css | ||
---- | ||
@import "./_common.less"; | ||
@import "lib/css-reset/reset.css"; | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/integTest/groovy/org/gradle/playframework/plugins/PlayLessPluginIntegrationTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.gradle.playframework.plugins | ||
|
||
import org.gradle.playframework.AbstractIntegrationTest | ||
|
||
import static org.gradle.playframework.fixtures.file.FileFixtures.findFile | ||
import static org.gradle.playframework.fixtures.Repositories.playRepositories | ||
import static org.gradle.playframework.plugins.PlayLessPlugin.LESS_COMPILE_TASK_NAME | ||
|
||
class PlayLessPluginIntegrationTest extends AbstractIntegrationTest { | ||
|
||
def setup() { | ||
buildFile << """ | ||
plugins { | ||
id 'org.gradle.playframework' | ||
id 'org.gradle.playframework-less' | ||
} | ||
${playRepositories()} | ||
""" | ||
} | ||
|
||
def "can compile LESS files"() { | ||
given: | ||
File lessDir = temporaryFolder.newFolder('app', 'assets', 'stylesheets') | ||
new File(lessDir, 'main.less') << lessSource() | ||
|
||
when: | ||
build(LESS_COMPILE_TASK_NAME) | ||
|
||
then: | ||
File outputDir = file('build/src/play/less') | ||
outputDir.isDirectory() | ||
|
||
File[] cssFiles = new File(outputDir, 'stylesheets').listFiles() | ||
cssFiles.length == 1 | ||
findFile(cssFiles, 'main.css') | ||
} | ||
|
||
def "can add source directories to default source set"() { | ||
given: | ||
File lessDir = temporaryFolder.newFolder('app', 'assets', 'stylesheets') | ||
new File(lessDir, 'main.less') << lessSource() | ||
|
||
File extraLessDir = temporaryFolder.newFolder('extra', 'less', 'stylesheets') | ||
new File(extraLessDir, 'extra.less') << lessSource() | ||
|
||
buildFile << """ | ||
sourceSets { | ||
main { | ||
less { | ||
srcDir 'extra/less' | ||
} | ||
} | ||
} | ||
""" | ||
|
||
when: | ||
build(LESS_COMPILE_TASK_NAME) | ||
|
||
then: | ||
File outputDir = file('build/src/play/less') | ||
outputDir.isDirectory() | ||
|
||
File[] cssFiles = new File(outputDir, 'stylesheets').listFiles() | ||
cssFiles.length == 2 | ||
findFile(cssFiles, 'main.css') | ||
findFile(cssFiles, 'extra.css') | ||
} | ||
|
||
static String lessSource() { | ||
""" | ||
.some-class { | ||
float: left; | ||
} | ||
""" | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...t/groovy/org/gradle/playframework/plugins/PlayLessWithWebJarsPluginIntegrationTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.gradle.playframework.plugins | ||
|
||
import org.gradle.playframework.AbstractIntegrationTest | ||
|
||
import static org.gradle.playframework.fixtures.Repositories.playRepositories | ||
import static org.gradle.playframework.fixtures.file.FileFixtures.findFile | ||
import static org.gradle.playframework.plugins.PlayLessPlugin.LESS_COMPILE_TASK_NAME | ||
|
||
class PlayLessWithWebJarsPluginIntegrationTest extends AbstractIntegrationTest { | ||
|
||
def setup() { | ||
buildFile << """ | ||
plugins { | ||
id 'org.gradle.playframework' | ||
id 'org.gradle.playframework-less' | ||
id 'org.gradle.playframework-webjars' | ||
} | ||
${playRepositories()} | ||
dependencies { | ||
webJar 'org.webjars.bower:css-reset:2.5.1' | ||
} | ||
""" | ||
} | ||
|
||
def "can compile LESS files which import files in WebJars"() { | ||
given: | ||
File lessDir = temporaryFolder.newFolder('app', 'assets', 'stylesheets') | ||
new File(lessDir, 'main.less') << lessSource() | ||
|
||
when: | ||
build(LESS_COMPILE_TASK_NAME) | ||
|
||
then: | ||
File outputDir = file('build/src/play/less') | ||
outputDir.isDirectory() | ||
|
||
File[] cssFiles = new File(outputDir, 'stylesheets').listFiles() | ||
cssFiles.length == 1 | ||
findFile(cssFiles, 'main.css') | ||
} | ||
|
||
static String lessSource() { | ||
""" | ||
@import (inline) "lib/css-reset/reset.css"; | ||
.some-class { | ||
float: left; | ||
} | ||
""" | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...integTest/groovy/org/gradle/playframework/plugins/PlayWebJarsPluginIntegrationTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.gradle.playframework.plugins | ||
|
||
import org.gradle.playframework.AbstractIntegrationTest | ||
|
||
import static org.gradle.playframework.fixtures.Repositories.playRepositories | ||
import static org.gradle.playframework.fixtures.file.FileFixtures.findFile | ||
import static org.gradle.playframework.plugins.PlayWebJarsPlugin.WEBJARS_EXTRACT_TASK_NAME | ||
|
||
class PlayWebJarsPluginIntegrationTest extends AbstractIntegrationTest { | ||
|
||
def setup() { | ||
buildFile << """ | ||
plugins { | ||
id 'org.gradle.playframework' | ||
id 'org.gradle.playframework-webjars' | ||
} | ||
${playRepositories()} | ||
dependencies { | ||
webJar 'org.webjars:requirejs:2.3.6' | ||
webJar 'org.webjars.npm:inherits:2.0.4' | ||
} | ||
""" | ||
} | ||
|
||
def "can extract WebJars"() { | ||
when: | ||
build(WEBJARS_EXTRACT_TASK_NAME) | ||
|
||
then: | ||
File outputDir = file('build/src/play/webJars/lib') | ||
outputDir.isDirectory() | ||
|
||
File[] libs = outputDir.listFiles() | ||
libs.length == 2 | ||
findFile(libs, 'requirejs') | ||
findFile(libs, 'inherits') | ||
} | ||
} |
Oops, something went wrong.