So when a dependency is requested in this format:
require(
function (CAS) {
$(function() {
CAS.start();
});
}
);
requirejs will find and load modules/cas.app.js just fine. Works great. But I also have a minified version of cas.app.js and I would like that to be the file that is loaded in a "production" environment. Thought I could get around this by creating a little plugin that would tack a .min to the end of the module name based like so:
/*!
* env.js
*/
define(['module'], function(module) {
'use strict';
var env,
masterConfig = (module.config && module.config()) || {};
env = {
dynamic: true,
parseName: function(name) {
return name + (masterConfig.isProduction ? '.min' : '');
},
load: function (name, req, onLoad, config) {
var parsed = env.parseName(name),
toLoad = [];
toLoad.push(parsed);
req(toLoad, function (value) {
onLoad(value);
});
}
};
return env;
});
This was just a test to see if it was possible to pull something like this off... I changed the require() call at the top of the page to this:
require(
function (CAS) {
$(function() {
CAS.start();
});
}
);
and it worked! When the config value isProduction is set to 'true' the module 'modules/cas.app.min' was loaded! Set 'isProduction' to false and 'modules/
cas.app' was loaded. Where I ran into a problem was down the line in another module where I needed access to the 'CAS' object again....
define(function (require) {
var Marionette = require('marionette');
//create root controller
var RootController = Marionette.Controller.extend({
index: function () {
var CAS = require('env!modules/
cas.app);
}
});
return RootController;
});
I get this error:
Load timeout for modules: env!modules/cas.app_unnormalized2,env!modules/cas.app
What is going on here? The initial use of the plugin works... but the second call always fails. I have been pouring of the AMD specs, plugins documentation... and nothing seems to work. Is this even possible? Is there an easier way? I know I can use the optimizer and create one large file but I don't want to.... I just want to use the minified versions of the modules in production. THANK you in advance for whatever help I get...
Daniel