Plugin questions...

36 views
Skip to first unread message

Daniel Phoebus

unread,
Jun 18, 2013, 10:47:45 AM6/18/13
to amd-im...@googlegroups.com
So when a dependency is requested in this format:

require(
['modules/cas.app'],
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(
['env!modules/cas.app'],
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

John Hann

unread,
Jun 18, 2013, 4:44:18 PM6/18/13
to amd-im...@googlegroups.com
Hey David,

This looks like a bug to me. You may want to file an issue against the AMD loader you are using.

Also: I'm guessing that your use of `dynamic: true` isn't what you want. You probably want the same module to be loaded each time. 

Regards, 

-- John 

Sent from planet earth
--
You received this message because you are subscribed to the Google Groups "amd-implement" group.
To unsubscribe from this group and stop receiving emails from it, send an email to amd-implemen...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Daniel Phoebus

unread,
Jun 19, 2013, 9:22:11 AM6/19/13
to amd-im...@googlegroups.com
Hey John,

Thanks.  Using Require JS at the moment.  Just can't figure it out... so I will try to file a report like you said.

Daniel
Reply all
Reply to author
Forward
0 new messages