简体   繁体   中英

rails asset pipeline production precompile

I have a directory projName/vendor/assets/bootstrap/css/ I am in production mode. 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. Actually all the top level directories under vendor/assets and app/assets are missing in public assets/

Compiled assets are written to the location specified in config.assets.prefix . By default, this is the public/assets directory.

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 )

How exactly does this happen ?? -> Rails comes bundled with a rake task which will compile all this. That rake task is what is shown above.

Compiled assets are written to the location specified in config.assets.prefix . By default, this is the public/assets directory.

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.

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.

Hope this helped.

Here are few links for your reference

http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets

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 .)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM