资产管道预编译所有资产文件夹子目录 [英] Asset Pipeline Pre-Compile all asset folder sub directories
问题描述
我想保持自己的资产井井有条,但是,我遇到了预编译问题.它没有选择子目录.这是路径:
I like to keep my assets highly organized, however, I am running into an issue with precompile. It is not picking up the sub directories. Here are the paths:
assets
>fonts
>images
>>backgrounds
>>home
>>icons
一切都适用于dev,但prod =不行.在我的产品环境中,我已经做过了:
Everything works on dev, but prod = no go. In my prod environment I already do:
config.assets.enabled = true
config.assets.compile = true
config.assets.precompile += ['*.js', '*.ico', '*.png', '*.jpg']
config.assets.initialize_on_precompile = true
我当前正在我的application.rb文件中运行以下功能:
And I am currently running the following function in my application.rb file:
# Add All Asset Pipeline Sub Folders
Dir.glob("#{Rails.root}/app/assets/images/**/").each do |path|
config.assets.paths << path
end
这就是我一直在努力,没有多少运气的事情.我希望通过几行代码来动态提取所有创建/更改的目录,因此不必一一添加.....
This is what I have been working with no, with not much luck. I was hoping to dynamically pick up all directories created/changed etc with few lines of code so I do not have to add them one by one.....
# Add All Asset Pipeline Sub Folders
Dir.glob("#{Rails.root}/app/assets/images/**/").each do |path|
config.assets.paths << path
config.assets.precompile += ['#{path}/*']
end
有什么想法吗?
更新的解决方案:
我最终在生产rb中进行了以下操作:
I ended up going with the following in my production rb:
config.assets.precompile += ['*.js', '*.ico', '*.png', '*.jpg']
config.assets.precompile += [ Dir["#{Rails.root}/app/assets/images/**/*"].reject {|fn| File.directory?(fn) } ]
推荐答案
# Add All Asset Pipeline Sub Folders
Dir.glob("#{Rails.root}/app/assets/images/**/").each do |path|
.. # seems you include /assets/images sub directories, expand the path
Ruby命令:
Ruby command:
Dir.glob("#{Rails.root}/app/assets/images/**/")
返回位于
/图像
目录.我认为,您仅推入预编译器映像资产.有感觉吗?替换为:
directory. I assume, that you push to precompiler images assets only. Has a sense? Replace it with:
Dir.glob("#{Rails.root}/app/assets/**/")
这篇关于资产管道预编译所有资产文件夹子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!