As advertised, the rjs
in Play can
ensure that any JavaScript resources referenced from within a WebJar are automatically referenced from the jsdelivr CDN. In addition if any .min.js file is found then that will be used in place of .js. An added bonus here is that there is no change required to your html!
However, I cannot seem to get any of that to work.
- I tried running my Play app in production mode, and all my webjar javascripts are still being referenced as local.
- I do not see the
.min
version of javascript files being used in production. I cannot get dependency injection to work in production mode. For example, when I want to inject
jquery
in my code like thisdefine(['jquery'], function ($) { 'use strict'; console.log($.grep); return { sum: function (a, b) { return a + b; } }; });
I can get this to work fine in dev mode, but in production mode, the rjs
failed saying
[info] Error: ENOENT, no such file or directory '/Users/khanguyen/Desktop/rjsdemo/target/web/rjs/build/js/jquery.js'
[info] In module tree:
[info] main
[info] app
[info]
[info] Error: Error: ENOENT, no such file or directory '/Users/khanguyen/Desktop/rjsdemo/target/web/rjs/build/js/jquery.js'
[info] In module tree:
[info] main
[info] app
[info]
[info] at Error (native)
Obviously it is looking at the wrong location for jQuery, despite the config setup generated by Webjar
requirejs.config({"paths":{"jquery":["/webjars/jquery/1.11.1/jquery","jquery"]},"shim":{"jquery":{"exports":"$"}},"packages":[]}) }
to have the correct location for jquery
.
I am using Play 2.4.0, with pipelineStages := Seq(rjs, digest)
setup in my build.sbt.
Please let me know where I got it wrong.
Thanks!