Question

in requirejs Is it ok to shim the minified version of a file? Is there a difference to shim minified or non-minified versions of a file ? Is there any impact?

For example I have requireJS config like:

require.config({    
    baseUrl: "js/",

    paths: {        
        jquery: "../lib/bower_components/jquery/jquery.min",,
        bootstrap: '../lib/bower_components/bootstrap/bootstrap.min',
    angular: '../lib/bower_components/angular/angular',
        angularCookies: '../lib/bower_components/angular-cookies/angular-cookies',
        angularResource: '../lib/bower_components/angular-resource/angular-resource',   
    angularRoute: '../lib/bower_components/angular-route/angular-route'
    },  

    shim: {
        "jquery": {"exports": "jquery"},
        "bootstrap" : {deps:['jquery']},            
        "angular": {
            "deps": ["jquery"],
            "exports": "angular"
        },
        "angularResource": {
            "deps": ["angular"],
            exports: "angularResource"
        },
        "angularRoute":{
            "deps": ['angular']
        },
        "angularCookies":{
            "deps": ['angular']
        } 
    },  
    priority: [
        "angular"
    ]

});
Was it helpful?

Solution

As far as RequireJS is concerned, shimming the unminified version or the minified version amounts to the same thing, provided that the minified version is functionally equivalent to the unminified version. (That is, the minification only compresses the file, and changes nothing else.)

While answering questions here I've run across a few libraries (that I don't use myself) that distribute a minified version of their code which is significantly different from their unminified version. In one case the unminified version would act as an AMD module and does not need a shim but the minified version did not act as an AMD module and would need a shim. So there may be cases where going from minified to unminified, or the other way around, means changing the shim configuration. You have to read your libraries' documentation to know (or read the source code).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top