Minify client through Play Framework

折月煮酒 提交于 2019-12-06 11:53:09

问题


How can I minify JS & CSS through play-framework?

'Google Closure Compiler' is no longer an option since it was removed.

I am using play Activator 2.3.7

Note: This question is not duplicate since Google Closure Compiler was removed from activator 2.3.7.


回答1:


Play 2.4 is the same.

  • Add empty main.js to public folder

  • plugins.sbt:

    addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7")
    
  • build.sbt:

    pipelineStages := Seq(rjs)
    
  • Generate production executable:

    $activator stage
    
  • Run results:

    ./target/universal/stage/bin/<yourproject>
    

Note: when running activator stage you should see it output the process of minifying/uglifying:

...

[info] Tracing dependencies for: main

[info] Uglify2 file: /path/to/your/project/public/something.js

...




回答2:


You can use RequireJS. It is documented here, but basically is just to add the following in the build.sbt

pipelineStages := Seq(rjs)

Then add this line to the file project/plugins.sbt

addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7")

As RequireJS website states

Combines related scripts together into build layers and minifies them via UglifyJS (the default) or Closure Compiler (an option when using Java).

Optimizes CSS by inlining CSS files referenced by @import and removing comments.



来源:https://stackoverflow.com/questions/29272840/minify-client-through-play-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!