[英]rails asset pipeline production precompile
I have a directory projName/vendor/assets/bootstrap/css/
I am in production mode. 我有一个目录projName/vendor/assets/bootstrap/css/
我处于生产模式。 production.rb contains: config.assets.precompile << /(^[^_\\/]|\\/[^_])[^\\/]*$/
when I run rake assets:precompile I get projName/public/assets/css/
but I want projName/public/assets/bootstrap/css/
I do not understand why the bootstrap directory is not there. production.rb包含:config.assets.precompile << /(^[^_\\/]|\\/[^_])[^\\/]*$/
当我运行rake资产时:precompile我得到projName/public/assets/css/
但我想要projName/public/assets/bootstrap/css/
我不明白为什么引导目录不存在。 Actually all the top level directories under vendor/assets and app/assets are missing in public assets/
实际上, public assets/
中缺少供应商/资产和应用/资产下的所有顶级目录。
Compiled assets are written to the location specified in config.assets.prefix
. 编译后的资产将写入config.assets.prefix
指定的位置。 By default, this is the public/assets
directory. 默认情况下,这是public/assets
目录。
To understand this you have to first understand what precompiling is and does. 要了解这一点,您必须首先了解什么是预编译和做什么。 Let me explain 让我解释
When you run (a rake task) 运行时(耙任务)
rake assets:precompile
it will create a public
folder inside your application folder which will compile all your asset manifests (ie. your application.css
and application.js
) 它会创建一个public
应用程序文件夹内的文件夹,这将编译你的所有资产清单(即你的application.css
和application.js
)
How exactly does this happen ?? 这到底是怎么发生的? -> Rails comes bundled with a rake task which will compile all this. -> Rails捆绑了一个rake任务,它将编译所有这些。 That rake task is what is shown above. 上面显示的是该耙任务。
Compiled assets are written to the location specified in config.assets.prefix
. 编译后的资产将写入config.assets.prefix
指定的位置。 By default, this is the public/assets
directory. 默认情况下,这是public/assets
目录。
The default matcher for compiling files includes application.js, application.css and all non-JS/CSS files (this will include all image assets automatically) from app/assets folders including your gems. 用于编译文件的默认匹配器包括application / assets文件夹(包括您的gems)中的application.js,application.css和所有非JS / CSS文件(这将自动包括所有图像资产)。
And thats exactly what that regex means (to include everything in your app/assets folder), you can also explicitly provide it as shown in the answer above. 这正是regex的含义(将所有内容包括在app / assets文件夹中),您也可以显式提供它,如上面的答案所示。
Hope this helped. 希望这会有所帮助。
Here are few links for your reference 这里有一些链接供您参考
http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets
http://dennisreimann.de/blog/precompiling-rails-assets-for-development/ http://dennisreimann.de/blog/precompiling-rails-assets-for-development/
What does that regex mean? 正则表达式是什么意思? If you want to precompile everything, try this. 如果要预编译所有内容,请尝试此操作。
config.assets.precompile = ['*.js', '*.css']
Actually, if you want to precompile everything, try this: 实际上,如果您想预编译所有内容,请尝试以下操作:
def precompile?(path)
%w(app lib vendor).each do |asset_root|
assets_path = Rails.root.join(asset_root, 'assets').to_path
return true if path.starts_with?(assets_path)
end
false
end
# Precompile all assets under app/assets (unless they start with _)
Rails.application.config.assets.precompile << proc do |name, path|
starts_with_underscore = name.split('/').last.starts_with?('_')
unless starts_with_underscore
path = Rails.application.assets.resolve(name).to_path unless path # Rails 4 passes path; Rails 3 doesn't
precompile?(path)
end
end
(Based on the code in the Rails Guide .) (基于Rails Guide中的代码 。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.