Domanda

OK, so my problem is that I'd like to be able to automatically delete parts of the shim config I've set up for RequireJS; rather than loading the entire minified Bootstrap file I split it up into the different plugins, so that I get the benefit of less filesize when my application uses less of the Bootstrap components. E.g:

require.config({
    paths : {
        jquery     : 'vendor/jquery/jquery.min',
        bootstrap  : 'vendor/bootstrap-sass/js'
    },
    shim : {
        'bootstrap/affix': { deps: ['jquery'], exports: '$.fn.affix' },
        'bootstrap/alert': { deps: ['jquery'], exports: '$.fn.alert' },
        'bootstrap/button': { deps: ['jquery'], exports: '$.fn.button' },
        'bootstrap/carousel': { deps: ['jquery'], exports: '$.fn.carousel' },
        'bootstrap/collapse': { deps: ['jquery'], exports: '$.fn.collapse' },
        'bootstrap/dropdown': { deps: ['jquery'], exports: '$.fn.dropdown' },
        'bootstrap/modal': { deps: ['jquery'], exports: '$.fn.modal' },
        'bootstrap/popover': { deps: ['jquery'], exports: '$.fn.popover' },
        'bootstrap/scrollspy': { deps: ['jquery'], exports: '$.fn.scrollspy'        },
        'bootstrap/tab': { deps: ['jquery'], exports: '$.fn.tab' },
        'bootstrap/tooltip': { deps: ['jquery'], exports: '$.fn.tooltip' },
        'bootstrap/transition': { deps: ['jquery'], exports: '$.support.transition' },
    }
});

Whilst the r.js optimizer correctly identifies that I'm only using bootstrap/dropdown, it still includes the shim config for files that don't end up in the production code. So my question is can I get rid of the unused shim files automatically? I'm using grunt-contrib-requirejs for the actual optimization and have had no problems with that. A Grunt based solution would be preferable but I'm open to anything else. Thanks.

È stato utile?

Soluzione

To summarize the great points made above, and hopefully close the question

  • Unused shim configs are not removed by r.js since it can't know if you need them at run-time
  • ~175 bytes (gzipped) are not worth manually optimizing, especially as part of a payload 200 times that big, and won't cause noticeable improvement
  • AMDClean could be an automated way to de-AMDify your scripts completely and thus meet your size-saving desires
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top