Play Framework 2 & requirejs - paths that are not followed in dist build

I am having problems implementing requirejs in Play 2.0, where in dev mode all modules can be found, but when I run dist, it seems that the paths that I have installed are not being followed.

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 call:

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

in my build.scala I tell you which files to optimize like this:

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

Client side all dependencies are allowed, but when using dist for optimization, 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 see, the config path is ignored and therefore it resolves the paths incorrectly. this seems to be due to app.build.js overriding the configuration in main.js.

Has anyone encountered this problem before?

Thanks,

Floor

+7
source share
1 answer

I had an identical problem and adding the requireJsShim key to my assembly. Bug fixed:

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

requireJsShim tells the game to use options in your main.js, such as paths and pads, instead of the default values ​​in games app.build.js

I am using Play 2.1.0; this feature was not added until December 12, 2012, so I'm not sure which candidates for version 2.1 are included in

Literature:
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

+8
source

All Articles