Bootstrapping the applications
When we linked require.js
to our application, we told it to use main.js
as our entry point. To test that this works, let's start by entering a dummy main.js
. JavaScript files in Play applications go in /public/javascripts
:
// public/javascripts/main.js require([], function() { console.log("hello, JavaScript"); });
To verify that this worked, head to 127.0.0.1:9000
and open the browser console. You should see "hello, JavaScript"
in the console.
Let's now write a more useful main.js
. We will start by configuring RequireJS, giving it the location of modules we will use in our application. Unfortunately, NVD3, the graph library that we use, does not play very well with RequireJS so we have to use an ugly hack to make it work. This complicates our main.js
file somewhat:
// public/javascripts/main.js (function (requirejs) { 'use strict'; // -- RequireJS config -- requirejs.config({ // path to the web jars. These...