好的,所以我的問題是我希望能夠自動刪除我爲RequireJS設置的shim配置的一部分;而不是加載整個縮小的Bootstrap文件,我將其分解到不同的插件中,以便在應用程序使用較少的Bootstrap組件時獲得較少文件大小的好處。 E.g:在RequireJS中刪除未使用的shim配置文件?
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' },
}
});
雖然r.js
優化正確識別我只使用bootstrap/dropdown
,它仍包括不生產代碼的最終文件的墊片配置。所以我的問題是我可以自動擺脫未使用的墊片文件?我正在使用grunt-contrib-requirejs
進行實際優化,並且沒有任何問題。一個基於Grunt的解決方案將是可取的,但我對任何其他方面都是開放的。謝謝。
只是好奇......爲什麼?是不是隻有12(或更少)行 – explunit
和〜700字節的代碼,是的,但在一個約550KB(引導,requirejs,下劃線,主幹,d3,jquery和自定義代碼)的「優化」可以做的減少文件大小是值得做的。 – Ben
因此,爲了減少你的代碼,爲什麼不從每個jQuery插件中移除'exports'?對我來說似乎沒用。 – gustavohenke