Woops, I'm not sure how the explanation got lost!
The script include:
<script id="requirejs" data-rev="1485975293" data-main="main.js?rev=1485975293" src="require.js?rev=1485975293"></script>
Alright, so this is in my main.js (data-main) file, that requirejs uses for loading up the dependencies and all that.
I'm just posting the relevant code block here (notice the Drupal.attachBehaviors(document, Drupal.settings);
at the end:
require([
'jquery',
'underscore',
'intentcontext',
'app',
'primary-menu'
], function ($, _, IntentContext, app) {
'use strict';
// DOM ready
$(function() {
// js loaded only on homepage
if ($('body').hasClass('front')) {
require(['homepage']);
}
/*
* loaded js for foundation and intention
*/
require(['foundation']);
require(['intentinit']);
// call drupal behaviors
Drupal.attachBehaviors(document, Drupal.settings);
}); // DOM ready
});
And then example of a dependent js module (primary-menu.js):
define([
'jquery',
'intentcontext'
], function ($, IntentContext) {
'use strict';
/*
* constructor
*/
var PrimaryMenu = function(context, settings) {
var
self = this;
self.$elm = $(context).find('#block-system-main-menu');
$('body').once('primaryMenu').each(function() {
self.init();
});
}; // PrimaryMenu constructor
/*
* on document ready with drupal behaviors
*/
(function($, Drupal) {
Drupal.behaviors.primaryMenu = {
attach: function(context, settings) {
var
primaryMenu = new PrimaryMenu(context, settings);
}
};
}(jQuery, Drupal));
});
Hope that helps.