user2379285
user2379285

Reputation: 1

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/

Upvotes: 0

Views: 473

Answers (3)

AlexChaffee
AlexChaffee

Reputation: 8252

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

Upvotes: 0

Nikhil Nanjappa
Nikhil Nanjappa

Reputation: 6652

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/

Upvotes: 1

tungsten_carbide
tungsten_carbide

Reputation: 555

What does that regex mean? If you want to precompile everything, try this.

config.assets.precompile = ['*.js', '*.css']

Upvotes: 0

Related Questions