How to use requirejs in a game system with a custom folder structure

I just switched to play framework 2.10 and would like to use RequireJS. I really have a user folder structure (too lazy to write javascripts all the time, so its / js /;). while dist I get the following error:

Error: ERROR: module path does not exist: / tmp / build_udsbfo9u2iwl / target / scala-2.10 / classes / public / javascripts / app.js for a module named: app. The path refers to: / tmp / build_udsbfo9u2iwl [info] Optimization optimization required.

So the requirement clearly only looks in the javascripts folder. I think there should be a place where the folder is configured, but I could not find it.

So, how can I configure requireJs in play framework 2.10 to use my folders for optimization?

+5
source share
1 answer

Set the value of requireJsFolder in Build.scala:

import sbt._
import Keys._
import play.Project._

object ApplicationBuild extends Build {

  val appName         = "play-2-1-features"
  val appVersion      = "1.0-SNAPSHOT"

  val appDependencies = Seq(
    jdbc,
    anorm,
    "junit" % "junit-dep" % "4.11" % "test"
  )

  val main = play.Project(appName, appVersion, appDependencies).settings(
    requireJs += "main.js"
    , requireJsFolder := "js" //changes location from javascripts to js
  )
}

Then you can use it in your templates:

@helper.requireJs(core = routes.Assets.at("javascripts/require.js").url, module = routes.Assets.at("js/main").url)

Here is my sample project https://github.com/schleichardt/play-2.1-features/tree/stackoverflow-question-14924134 (note: it is not in the main branch)

+9
source

All Articles