-
Notifications
You must be signed in to change notification settings - Fork 0
AssetsGoogleClosureCompiler
The Closure Compiler is a tool for making JavaScript download and run faster. It is a true compiler for JavaScript - though instead of compiling from a source language to machine code, it compiles JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what’s left.
Any JavaScript file present in app/assets
will be parsed by Google Closure compiler, checked for errors and dependencies and minified if activated in the build configuration.
JavaScript code is compiled during the compile
command, as well as automatically when modified. Error are shown in the browser just like any other compilation error.
A minified file is also generated, where .js
is replaced by .min.js
. In our example, it would be test.min.js
. If you want to use the minified file instead of the regular file, you need to change the script source attribute in your HTML.
By default, any JavaScript file not prepended by an underscore will be compiled. This behavior can be changed in project/Build.scala
by overriding the javascriptEntryPoints
key. This key holds a PathFinder
.
For example, to compile only .js
file from the app/assets/javascripts/main
directory:
val main = PlayProject(appName, appVersion, mainLang = SCALA).settings(
javascriptEntryPoints <<= baseDirectory(base =>
base / "app" / "assets" / "javascripts" / "main" ** "*.js"
)
)
The default definition is:
javascriptEntryPoints <<= (sourceDirectory in Compile)(base =>
((base / "assets" ** "*.js") --- (base / "assets" ** "_*")).get
)
- Working with public assets
- Using CoffeeScript
- Using LESS CSS
- Using Google Closure Compiler
- Using RequireJs
- Installing Play
- Creating a new application
- Anatomy of a Play application
- Using the Play console
- Setting-up your preferred IDE
- Sample applications