如何缩小宝石的大小 [英] How to reduce the size of a gem

查看:92
本文介绍了如何缩小宝石的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在创建一个宝石,它似乎比比较宝石更大。

首先这是一个真正的问题,如果是的话有没有减少宝石大小的特殊方法?



宝石: https://rubygems.org/gems/roroacms



Github: https://github.com/roroacms/roroacms

解决方案

spec / 目录在解压缩后已超过99MB。你一定要把它从最终的宝石中排除出去(即使很小)。这么大的原因是它包含了带有 log / (80MB)和 tmp / (18MB)的虚拟应用程序,目录仍然存在。



您排除文件的方式是通过中的文件变量> gemspec 。该变量包含每个文件的数组,这些文件将被放入构建好的gem中。

  Gem :: Specification.new do | gem | 
gem.files =`git ls-files`.split($ /)。reject {| fn | fn.start_with? spec}
...
end

代码将首先获得目录中每个文件的列表(使用 git ls-files 它也会应用来自 .gitignore 的规则)然后删除任何路径以 spec >开头的文件。



这取决于您是否要包含测试在最后的宝石或不是。问题是没有简单的方法来运行测试。曾经有一个选项( -t )直接通过Rubygems来完成,但是这个选项在很久以前就被删除了。考虑到这种情况,我认为最好将测试保存在存储库中。



请注意,您可能还会看到一个名为的变量, test_files gemspec 中。该变量已被弃用,并没有做任何事情。

I am currently in the process of creating a gem and it seems to be considerably bigger than comparative gems.

First of all is this really an issue and if so is there a particular way to reduce the size of the gem?

Gem: https://rubygems.org/gems/roroacms

Github: https://github.com/roroacms/roroacms

解决方案

The gem's spec/ directory has, when unpacked, over 99MB. You should definitely exclude it from the final gem (even if small). The reason it's so large is because it contains the dummy app with log/ (80MB) and tmp/ (18MB) directories still present.

The way you exclude the files is though the files variable in the gemspec. The variable holds an array of every file that will be put into the built gem.

Gem::Specification.new do |gem|
    gem.files = `git ls-files`.split($/).reject { |fn| fn.start_with? "spec" }
    ...
end

The code will first get the list of every file in the directory (with git ls-files it will also apply the rules from .gitignore) and then removes any file whose path starts with spec.

It's up to you whether you want to include the tests in the final gem or not. The problem is that there's not a easy way of runing the tests. There used to be an option (-t) to do that directly via Rubygems but that option has been removed quite some time ago. Given the situation, I think it's probably for the best to just keep the tests in the repository.

Note that you might also see a variable called test_files in a gemspec. That variable is deprecated and doesn't do anything.

这篇关于如何缩小宝石的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆