1
votes

Questions:

  • Is there a way to avoid manually defining paths and shims in requirejs for webjars and all their transitive dependencies? (Or at least for webjars that come with a requirejs.config() call)?
  • Is there a simple example (or seed) of a Play 2.3 app that uses webjars and requirejs with javascript packages that have transitive dependencies? (Where each transitive dependency doesn't have to be manually configured with a shim in the app's requirejs config block?)

Problem Description:

I'm migrating a project to play 2.3 and am running into some issues grok-ing how webjars+requirejs are supposed to integrate. Simple problem that illustrates my confusion:

I want to use angular-ui-calendar (https://github.com/webjars/angular-ui-calendar), so I add the following to build.sbt:

"org.webjars" % "angular-ui-calendar" % "0.8.1"

After the update, sbt pulls down the angular-ui-calendar web jar, as well as the dependencies specified in its pom.xml (jquery-ui and fullcalendar).

To use any of it though, I have to add a bunch of paths and shims to main.js containing my requirejs config... basically:

requirejs.config({
    paths: {
        'angular-ui-calendar' : ['../lib/angular-ui-calendar/calendar'],
        'jquery-ui' : ['../lib/jquery-ui/jquery-ui']
         /* ... */
    },
    shim: {
        'angular':
           exports: 'angular'
        'angular-ui-calendar':
           deps: ['angular', 'jquery-ui', 'fullcalendar']
           /* ... */
    }
 });

If all this manual shimming is necessary, what's the point of the requirejs.config()'s defined in some webjars? (For example: https://github.com/webjars/angular-ui-bootstrap/blob/master/src/main/resources/webjars-requirejs.js)

1

1 Answers

4
votes

It depends on how you use WebJars in Play. If you follow the WebJars Docs for Play then you can use the WebJars' RequireJS configs. The downside of this approach is that it doesn't work with sbt-rjs. If you follow the Play Docs for WebJars then you have to manually specify the RequireJS config. Ideally Play should add support for the WebJars' RequireJS configs.