问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/25544137/how-to-reduce-the-size-of-a-gem