Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use requirejs in play framework with custom folder structure

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

Error: ERROR: module path does not exist: /tmp/build_udsbfo9u2iwl/target/scala-2.10/classes/public/javascripts/app.js for module named: app. Path is relative to: /tmp/build_udsbfo9u2iwl [info] RequireJS optimization finished.

So require is obviously looking only in javascripts folder. i guess there must be some place where the folder is configured, but i was unable to find it.

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

like image 561
jan Avatar asked Feb 17 '13 17:02

jan


1 Answers

Set the requireJsFolder value 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 example project https://github.com/schleichardt/play-2.1-features/tree/stackoverflow-question-14924134 (note: it is not in master branch)

like image 82
Schleichardt Avatar answered Sep 22 '22 13:09

Schleichardt