好的,所以我的问题是我希望能够自动删除我为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