javascriptrequirejstest-environments

RequireJS: loading different files according environment


Is there any functionality to load different files according on current project environment (development or production for example)? I mean something, that helps me transparently loading minified or full files. I read about multiversion loading, but multiversioning means that I need to specify version of file.
For example I have module.js file with my module. In this file I need to load jQuery:

require(['jquery]);

But I have minified and full version of jQuery and I want to load different files. I am thinking about something like this in config:

   require.config({
        paths: {
            'jquery' : function(){
                if( MODE == 'DEV' ){
                    return 'jquery';
                }else{
                    return 'jquery.min'
                }
            }
        }
    });

Or, maybe, something similar.


Solution

  • If someone still want to know how to do that:

    require.config({
        paths: {
            'jquery' : (function(){
                if( MODE == 'DEV' ){
                    return 'jquery';
                }else{
                    return 'jquery.min'
                }
            })()
        }
    });
    

    This function is self invoking anonymous function. It invokes immediately in the definition place.