gpt4 book ai didi

javascript - 删除 RequireJS 中未使用的 shim 配置?

转载 作者:行者123 更新时间:2023-11-29 22:09:03 24 4
gpt4 key购买 nike

好的,所以我的问题是我希望能够自动删除我为 RequireJS 设置的部分 shim 配置;我没有加载整个缩小的 Bootstrap 文件,而是将其拆分为不同的插件,这样当我的应用程序使用较少的 Bootstrap 组件时,我可以获得较小的文件大小的好处。例如:

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,但它仍然包含用于未最终出现的文件的 shim 配置生产代码。所以我的问题是我可以自动删除未使用的 shim 文件吗?我正在使用 grunt-contrib-requirejs 进行实际优化,并且没有遇到任何问题。基于 Grunt 的解决方案会更可取,但我对其他任何事情都持开放态度。谢谢。

最佳答案

总结上面提出的要点,并希望结束这个问题

  • r.js 不会删除未使用的 shim 配置,因为它无法知道您在运行时是否需要它们
  • ~175 字节(gzip 压缩)不值得手动优化,尤其是作为 200 倍大的有效载荷的一部分,并且不会引起明显的改进
  • AMDClean可能是一种完全去 AMD 化您的脚本的自动化方式,从而满足您节省大小的需求

关于javascript - 删除 RequireJS 中未使用的 shim 配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19104854/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com