It turns out that I had a conflicting build.sbt
(in the root
directory) and Build.scala
(in the project
directory) files. Once I removed the sbt file, the requireJs optimization began working as expected
Playframework/RequireJs javascript files not being optimized
-
19-10-2022 - |
Question
I'm new to play framework and I'm trying to get it to work with RequireJs. When I run my app in dev mode everything runs fine, but when I set application.mode=prod
and start the server with play start
I'm running into problems.
The browser receives an HTTP404 when attempting to load /assets/javascripts-min/home/main.js.
Here's my Build.scala file
import sbt._
import Keys._
import play.Project._
import com.google.javascript.jscomp._
import java.io.File
object MyBuild extends Build {
val appDependencies = Seq (
jdbc,
anorm,
cache
)
val appVersion = "0.0.1"
val appName = "TodoList"
// set clojure compiler options so it won't choke on modern js frameworks
val root = new java.io.File(".")
val defaultOptions = new CompilerOptions()
defaultOptions.closurePass = true
defaultOptions.setProcessCommonJSModules(true)
defaultOptions.setCommonJSModulePathPrefix(root.getCanonicalPath + "/app/assets/javascripts/")
defaultOptions.setLanguageIn(CompilerOptions.LanguageMode.ECMASCRIPT5)
CompilationLevel.WHITESPACE_ONLY.setOptionsForCompilationLevel(defaultOptions)
val main = play.Project(appName, appVersion, appDependencies).settings(
(Seq(requireJs += "home/main.js", requireJsShim := "home/main.js") ++ closureCompilerSettings(defaultOptions)): _*
)
}
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow