播放2.2缩小javascripts

时间:2013-12-27 03:01:54

标签: minify google-closure-compiler playframework-2.2

如何告诉Play编译和创建my.js的缩小版本?运行'play stage'后,我无法在 target / scala-2.10 / resource_managed target / scala-2.10 / classes 下找到它。

app/
   assets/
      javascripts/
          main/
             some.js

编辑1:按照Raunak的评论,我试过这个。但是仍然没有创建缩小的js。

val main = play.Project(appName, appVersion, appDependencies)
.settings(
        ebeanEnabled := true,
        requireJs += "mainProd.js", // files specified in requireJs will be optimized
        requireJsShim += "build.js", // build options for optimizer
        requireJsFolder := "js",
        routesImport += "se.radley.plugin.salat.Binders._",
        templatesImport ++= Seq("org.bson.types.ObjectId"),
        resolvers += "Mave2" at "http://repo1.maven.org/maven2",
        resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/",
        resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
        resolvers += Resolver.sonatypeRepo("snapshots"),
        parallelExecution in Test := false,
        javascriptEntryPoints <<= baseDirectory(base =>
              base / "app" / "assets" / "javascripts" / "main" ** "*.js"
           )            
)

编辑2:我发现如果我给了javascriptEntryPoints,那么requireJsFolder中的所有js文件都不会被编译。

1 个答案:

答案 0 :(得分:0)

要运行minify进程,您可以按照documentation运行以下命令。

例如,要从app / assets / javascripts / main目录中仅编译.js文件:

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

检查在分段期间正常生成缩小

您可以使用play dist命令准备类似于play stage命令的独立应用程序版本,它将生成一个zip文件,而不是将代码写入目标目录。然后你可以检查缩小的文件是否存在