0

在我和我的同事身上发生过我们忘记在预编译文件列表中添加 a.js或 a的情况。.css我想更改production.rb文件以扫描 javascripts/stylesheets 文件夹,并将动态添加到config.assets.precompile变量中。代码看起来像这样:

def get_assets(folder,select_extensions,delete_from,remove_extensions)
  files     = Dir["#{folder}/**/*"].select {|e| select_extensions.include?(File.extname(e))}
  basenames = files.map {|e| e.sub(/.*#{delete_from}\//,"") }
  basenames.each do |bn|
    remove_extensions.each do |ext|
      bn.sub!(ext,"")
    end
  end
  basenames
end

在production.rb中,我会有这样的东西:

config.assets.precompile = get_assets("#{Rails.root}/app/assets/javascripts",[".js",".coffee"],"javascripts",[".coffee"]) + get_assets("#{Rails.root}/app/assets/stylesheets",[".css",".scss"],"stylesheets",[".scss"])

你看到我的想法有什么缺点/陷阱吗?

4

0 回答 0