I'm using require.js in play framework which is great. After tweaking Build.scala
file I'm getting minified js files on production but I'm not able to find any information about concatenation all the require.js modules into single js file?
I'll appreciate if anyone can shed any light or guide me in correct direction.
Do you know "webjars" ( http://www.webjars.org)? Webjars is a framework which provides you with Javascript and CSS libraries/frameworks in jar files. You can add them as dependencies to you build file. They also provide some helper-function, one of which "compiles" (concatenate and minify) the requirejs-stuff into one file.
Have a look at the documentation: http://www.webjars.org/documentation They provide a few simple examples.
I ran into a few 'gotchas' regarding the requireJS integration in Play, in 2.2.x.
a) Do not change your routes file assets location. Play's convention seems to be all public javascripts go into public/javascripts and your requireJS driver goes into app/assets/javascripts.
b) The build.sbt requireJS lines go at the bottom, beneath the "playJavaSettings" or "playScalaSettings" as such:
name := "TestContcatJS"
version := "1.0-SNAPSHOT"
libraryDependencies ++= Seq(
javaJdbc,
javaEbean,
cache
)
play.Project.playJavaSettings
requireJs += "main.js"
requireJsShim += "main.js"
c) You can reference the public javascripts in your driver using a relative path. Something like (in main.js):
require.config({
paths: {
'public-js': '../../public/javascripts'
}
});
require([
"public-js/foo",
"public-js/bar"
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With