How to enable the Closure compiler minimization feature in Play 2.0

According to the documentation here: https://github.com/playframework/Play20/wiki/AssetsGoogleClosureCompiler says:

Any JavaScript file present in the application / assets will be analyzed by the Google Closure compiler, checked for errors and dependencies, and will be reduced if it is activated in the assembly configuration.

However, I can’t find out how to install this in the build configuration, I tried adding the code:

val main = PlayProject(appName, appVersion, mainLang = SCALA).settings( javascriptEntryPoints <<= baseDirectory(base => base / "app" / "assets" / "javascripts" ** "*.js" ) ) 

in build.scala, however I cannot find mini JavaScript files.

Here are the steps I tried:

  • Add the above code to build.scala

  • Create a JavaScript file in app / assets / javascripts

  • Type "compile" on the Play console and note that no javascript files are created in app / assets / javascripts or public / javascripts.

However, I noticed that if I write some kind of invalid JavaScript, I will get an error message (for example, at 127.0.0.1:9000 - Compilation error), so it looks like the closing compiler checks for errors successfully, m not sure how perform minimization.

While on the issue of minimization, is it possible to use a regular (non-minified) JavaScript file only in development mode, but use the mini version during production?

thanks

+4
source share
1 answer

Play does not put assets in the public or asset folders after compiling them. Compiled assets (JS, Less or CoffeeScript) are placed inside:

/ target / scala [version] / resource_managed / master / ...

Play will then create a mapping to these files so that you can process the assets as if they live in the / public folder.

It should be noted that during development, compilation does not output files to this directory. When you click your localhost: 9000 path in the browser, this will do the final compilation and then output the files to a directory.

To answer the mini version (and to see the best example of how to change the build configuration), I recommend checking out Yann Simon's message when using Less in Play. This is conceptually the same process as JS, and it also has a great example of how to switch between non-minified / reduced versions based on the playback mode:

https://plus.google.com/u/0/108788785914419775677/posts/QgyUF9cXPkv

+3
source

Source: https://habr.com/ru/post/1402648/


All Articles