dimanche 25 octobre 2015

Rails asset pipeline concatenates application.css and js in development but not in production

We currently use the assest pipeline on our production server to precompile individual CSS and JavaScript assets, but don't combine them into a single file e.g. we have the following config:

config.assets.precompile += %w( *.js *css fonts/*)

I'm able to precompile the CSS and JavaScript files into a single CSS and single JS file on the development system configured with production settings. However, when I try to precompile on the production server I get no errors, just empty application.js and application.css files.

I've done a lot of reading up (including here on SO) and trying different things, but nothing seems to come close to being relevent. I'd love to hear any pointers or suggestions so the production application.css and application.js include the concatenated file contents.

Thanks in advance

Here are the relevent snippets of development and production configuration:

app/assets/stylesheets/application.css.scss.erb

/* ...
*= require cssexample1
*= require cssexample2
*/

app/assets/javascripts/application.js

//= require jsexample1
//= require jsexample2

config/application.rb

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end


module StudySoup
  class Application < Rails::Application


    # Enable the asset pipeline
    config.assets.enabled = true

    # Version of your assets, change this if you want to expire all your assets
    config.assets.version = '1.0'
  end
end

Development setup

This creates the compiled application.js and application.css exactly as expected

ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
'RUBY_VERSION' in irb: 1.9.3
rails: 3.2.1
rake: 10.4.2

config/environments/development.rb

config.assets.debug = false

config.serve_static_files = true
config.assets.compress = true
config.assets.compile = true
config.assets.digest = true
config.assets.precompile += %w( *.js *css fonts/*)

Compiled with:

rm -rf tmp/cache/*
RAILS_ENV=development bundle exec rake assets:clean assets:precompile

Results:

public/assets/manifest.yaml contains entries and public/assests/application.js and application.css (and cache-busting copies) now contain the concatenated files

Production setup

This creates an empty application.js and applciation.css :(

ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
'RUBY_VERSION' in irb: 2.1.2
rails version: 3.2.1
rake, version 10.4.2

config/environments/production.rb

config.serve_static_assets = true
config.assets.compress = true
config.assets.compile = true
config.assets.digest = true
config.assets.precompile += %w( *.js *css fonts/*)

Compiled with:

rm -rf tmp/cache/*
rake assets:clean assets:precompile

Results:

public/assets/manifest.yaml contains entries and public/assests/application.js and application.css (and cache-busting copies) exist BUT are empty (length 0)

Aucun commentaire:

Enregistrer un commentaire