Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework 2 & requirejs - paths not respected in dist build

I am having some trouble with the requirejs implementation in Play 2.0, where in dev mode all modules can be found, but when running dist it seems to be not respecting the paths I have setup.

Here is the setup:

/assets/javascripts/templates/template1/main.js:

require.config({
   baseUrl: "/assets/javascripts",
   paths : {
           jquery : [ 'core/lib/jquery/jquery-1.8.3' ],
           can : [ 'core/lib/canjs/can' ]
   }
});

require([ "jquery", "can", "core/global/moduleloader" ], function($, can, ml) {
   //do stuff

});

And in the template I am calling:

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

in my build.scala I am telling it which files to optimize like so:

val main = play.Project(appName, appVersion, appDependencies).settings(
    requireJs += "templates/template1/main"
)

Client side all dependencies are resolved, but when using dist to optimize, I get:

[info] RequireJS optimization has begun...
[info] app.build.js:
[info] ({appDir: "javascripts",
[info]           baseUrl: ".",
[info]           dir:"javascripts-min",
[info]           modules: [{name: "templates/template1/main"}]})
model contains 41 documentable templates

Tracing dependencies for: templates/template1/main
JavaException: java.io.FileNotFoundException:       /Users/paulsmith/Projects/Experiments/play/Moduluar/target/scala-2.10/classes/public/javascripts-min/jquery.js (No such file or directory)
In module tree:
    templates/template1/main

From what I can see, the paths config is being ignored and so it is resolving the paths incorrectly.. this seems to be due to the app.build.js overriding the config in the main.js.

Has anyone come across this issue before?

Thanks,

Paul

like image 246
Paul Smith Avatar asked Dec 24 '12 12:12

Paul Smith


People also ask

Is Play framework still used?

Play is rock-solid and used by hundreds of thousands of Java and Scala developers every month. Play is still extremely relevant to today's application and web development and has a passionate and very capable community around it ensuring that it has many good years left.

What is Play framework used for?

Play Framework makes it easy to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly architecture. Built on Akka, Play provides predictable and minimal resource consumption (CPU, memory, threads) for highly-scalable applications.

How do I run Play framework in Windows?

To run the Play framework, you need JDK 6 or later. If you are using MacOS, Java is built-in. If you are using Linux, make sure to use either the Sun JDK or OpenJDK (and not gcj, which is the default Java command on many Linux distros). If you are using Windows, just download and install the latest JDK package.


1 Answers

I was having the identical issue, and adding the requireJsShim key to my Build.scala fixed the issue:

val main = play.Project(appName, appVersion, appDependencies).settings( 
    requireJs += "main.js",
    requireJsShim += "main.js"
}

requireJsShim tells play to use the settings in your main.js, such as paths and shims, instead of the default values in plays app.build.js

I'm using Play 2.1.0; this feature wasn't added until December 12, 2012, so I'm not sure which Release Candidates of 2.1 it's included with

References:
https://play.lighthouseapp.com/projects/82401-play-20/tickets/945-allow-specifying-your-own-requirejs-build-file#ticket-945-4
https://github.com/playframework/Play20/commit/ba71f3967c3001cc0db8a4a7b4f9a31c8eebbc45

like image 170
Tommy Adamski Avatar answered Oct 12 '22 10:10

Tommy Adamski