4

I want to manage clientside assets using Bower which installs resources such as angular into

/vendors/assets/components/angular/angular.js

I reference these assets in the application.css.scss file as follows:

/* ...
*= require bootstrap
*/

However while this works ok for development and the files are included ok, they're not getting picked up by sprockets for compilation in production on Heroku.

How can I instruct Sprockets to pick up and compile files from /vendor/assets/components/?

Peter Nixey
  • 16,187
  • 14
  • 79
  • 133

1 Answers1

6

You should be able to tell the pipeline to include extra directories like this:

config.assets.paths << Rails.root.join('vendor', 'assets', 'components')

You may also need to tell it to precompile specific files too, as only the main application.js & application.css are precompiled by default:

config.assets.precompile << %w( frontpage.css frontpage.js *.svg )

With Rails 4 on Heroku you need to add the 12factorapp gem

Finally, if you are using Heroku then for Rails 4 you'll need to add the following Gem

group :production do
  gem 'rails_12factor'
end

See this question for more information

Community
  • 1
  • 1
Matt Gibson
  • 14,616
  • 7
  • 47
  • 79
  • I have already done that and it works in dev however it's not unfortunately working in production. It seems that Rails knows the files are there but Sprockets doesn't – Peter Nixey Oct 23 '13 at 17:01
  • Answer updated. You may need to tell it what specific extra files to precompile too. – Matt Gibson Oct 23 '13 at 19:46
  • Matt, what did you mean by application.js/.css being the only files compiled? All the files which are in their manifest are also precompiled too - surely that's the point of the asset pipeline no? – Peter Nixey Oct 24 '13 at 09:04
  • I mean that the top-level default manifests are compiled, but nothing outside of them. You need to tell it explicitly to compile any custom manifests you have, as well as the directories to look in for the files it references (if they are somewhere non-standard). The ones I have added in the answer are not referenced from the main manifests. Have you checked in the compiled asset directory on the production server? You should see the files there, with a name that has a hash appended to it if it's working. – Matt Gibson Oct 24 '13 at 10:57
  • your suggestion was correct, however there were two other issues. I'm going to edit your answer so that I can mark it correct, make it referenceable and give you the points. If you don't like the edits feel free to ditch them and I'll answer separately . – Peter Nixey Oct 29 '13 at 10:58
  • 1
    That makes sense re Heroku - I've been using Engine Yard so it worked without the gem. Thanks for editing and accepting. – Matt Gibson Oct 29 '13 at 12:39