Oracle JET includes the RequireJS library and sample bootstrap file in the Oracle JET download. To use RequireJS in your application, edit the bootstrap file to add the Oracle JET modules you need. You can also add your own modules as needed for your application code.
The code below shows the main-template.js bootstrap file distributed with Oracle JET. Typically, you place the bootstrap file in your application's js directory and rename it to main.js . The comments in the code describe the purpose of each section. The sections that you normally edit are highlighted in bold.
requirejs.config({
// Path mappings for the logical module names
paths: {
'knockout': 'libs/knockout/knockout-3.3.0',
'jquery': 'libs/jquery/jquery-2.1.3.min',
'jqueryui-amd': 'libs/jquery/jqueryui-amd-1.11.4.min',
'ojs': 'libs/oj/v1.1.2/min',
'ojL10n': 'libs/oj/v1.1.2/ojL10n',
'ojtranslations': 'libs/oj/v1.1.2/resources',
'signals': 'libs/js-signals/signals.min',
'crossroads': 'libs/crossroads/crossroads.min',
'text': 'libs/require/text',
'promise': 'libs/es6-promise/promise-1.0.0.min',
'hammerjs': 'libs/hammer/hammer-2.0.4.min'
},
// Shim configurations for modules that do not expose AMD
shim: {
'jquery': {
exports: ['jQuery', '$']
},
'crossroads': {
deps: ['signals'],
exports: 'crossroads'
}
},
// This section configures the i18n plugin. It is merging the Oracle JET built-in translation
// resources with a custom translation file.
// Any resource file added, must be placed under a directory named "nls". You can use a path mapping or you can define
// a path that is relative to the location of this main.js file.
config: {
ojL10n: {
merge: {
//'ojtranslations/nls/ojtranslations': 'resources/nls/myTranslations'
}
}
}
});
/**
* A top-level require call executed by the Application.
* Although 'ojcore' and 'knockout' would be loaded in any case (they are specified as dependencies
* by the modules themselves), we are listing them explicitly to get the references to the 'oj' and 'ko'
* objects in the callback
*
* For a listing of which JET component modules are required for each component,
* see the specific component demo pages in the JET cookbook.
*/
require(['ojs/ojcore', 'knockout', 'jquery', 'ojs/knockout', 'ojs/ojbutton', 'ojs/ojtoolbar', 'ojs/ojmenu'],
// add additional JET component libraries as needed
function(oj, ko, $) // this callback gets executed when all required modules are loaded
{
// add any startup code that you want here
}
);
To use RequireJS in an Oracle JET Application: