How to use requirejs

Comprehensive requirejs code examples:

How to use requirejs.define:

37
38
39
40
41
42
43
44
45
46
//
// this.MODULE_NAME = MODULE_NAME;
// e.g. in xmldom.js: this.CSL_CHROME = CSL_CHROME;
//
var shimDefine = function (path, dependencies, exports) {
        requirejs.define(path, dependencies, function () {
                var actualPath = path;

                if ("path" in requireConfig && path in requireConfig.paths) {
                        console.log(path + " in paths");

How to use requirejs.undef:

35
36
37
38
39
40
41
42
43
44
logger.verbose('Unloading cached copies of server.js files in ' + coursePath + ' ...');
var count = 0;
async.each(_.keys(requirejs.s.contexts._.defined), function(modPath, callback) {
    if (_.startsWith(modPath, coursePath)) {
        count++;
        requirejs.undef(modPath);
    }
    callback(null);
}, function(err) {
    if (ERR(err, callback)) return;

How to use requirejs.optimize:

101
102
103
104
105
106
107
108
109
110
    return {config, configFile};
}

async function doBuilds() {
    function callOptimizer(theConfig) {
        return new Promise((res, rej) => requirejs.optimize(theConfig, res, rej));
    }

    const {config, configFile} = await prepare();
    const result = await callOptimizer(config);

How to use requirejs.config:

30
31
32
33
34
35
36
37
38
  ;
// This is the setup for requirejs to load the browserConfig method
// the browser configuration is then used to configure the optimizer.
// It's easy to get confused here, by all the different targets for
// the same configuration ...
requirejs.config({
    baseUrl: baseUrl
});
configure = requirejs('bower_components/Atem-RequireJS-Config/browserConfig');