Reputation: 7230
I am coming from the Rails world and are now playing with play (2.1). I like that it comes with a kind of asset pipeline, but one thing I am missing is to include web-dependencies there. In Rails, I can add the jquery-rails
dependency and include it in my application.js file to make it available.
I stumbled upon http://webjars.org which seems nice, but as far as I can tell I can only include the files directly in a html file.
Is there any way to enable this kind of behavior, or is it planed to be implemented in the near future?
Upvotes: 1
Views: 864
Reputation: 11274
It's not supported in the same way as in Rails (apparently), so the best I've come up with is the following:
/app/assets/javascripts
So, for example, let's say you want to use AngularJS.
Build.scala:
val appDependencies = Seq(
"org.webjars" % "webjars-play" % "2.1.0-2",
"org.webjars" % "angularjs" % "1.0.7"
)
conf/routes
GET /webjars/*file controllers.WebJarAssets.at(file)
app/assets/javascripts/main.js
require(["webjars!angular.js"], function() {
console.log(angular.isString(3));
}
app/views/example.scala.html
...
@helper.requireJs(core = routes.Assets.at("javascripts/require.js").url, module = routes.Assets.at("javascripts/main").url)
...
Now the JavaScript console prints "false".
Upvotes: 3