rstacruz / sinatra-assetpack

Package your assets transparently in Sinatra.
http://ricostacruz.com/sinatra-assetpack/
MIT License
541 stars 97 forks source link

Not serving concatenated minimized files in production #79

Closed spullen closed 11 years ago

spullen commented 11 years ago

In production it just seems to be doing the same thing as it does in development, serves each individual file. I have the prebuild flag set to true, and I see it create both the js and css minimized files. And if I explicitly go to those files in the browser they exist.

Here is my assets config

class MyApp < Sinatra::Base
  ...
  set :root, File.dirname(__FILE__)

  register Sinatra::AssetPack
  ...

  assets {
    serve '/js',      :from => 'public/javascripts'
    serve '/css',     :from => 'public/stylesheets'
    serve '/images',  :from => 'public/img'

    js :app, '/js/app.js', [
      '/js/jquery-1.9.1.min.js',
      '/js/jquery.validate.min.js',
      '/js/knockout-2.2.1.min.js',
      '/js/bootstrap.min.js',
      '/js/application.js'
    ]

    css :application, '/css/application.css', [
      '/css/bootstrap.min.css',
      '/css/bootstrap-responsive.min.css',
      '/css/my_app.css'
    ]

    js_compression  :jsmin
    css_compression :simple

    prebuild true
  }

  ...
end

In my view I have

<%= css :application, :media => 'screen' %>
<%= js :app %>

And the output from thin start -p 4567 -e production or rackup -p 4567 -E production:

>> Using rack adapter
** Building /js/app.js...
** Building /css/application.css...
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:4567, CTRL+C to stop

Edit: Also, I'm using sinatra-assetpack 0.1.5

j15e commented 11 years ago

Try without prebuild true, this feature might be broken (haven't read the whole code yet and this part is still mysterious to me).

spullen commented 11 years ago

This might be an issue with https://github.com/sinatra/sinatra/issues/577 Which would cause this https://github.com/rstacruz/sinatra-assetpack/blob/master/lib/sinatra/assetpack/helpers.rb#L47 not to work properly.

In my app I printed out settings.production?.to_s and that returned false! even though settings.environment # => :production.

spullen commented 11 years ago

I tried removing the prebuild true, no dice.

j15e commented 11 years ago

Can you also try setting RACK_ENV=production as it might depends on it? Not sure what -e production does exactly.

spullen commented 11 years ago

setting the RACK_ENV explicitly didn't work either.

j15e commented 11 years ago

And downgrading or upgrading sinatra? Last tests were run with 1.3.4 not 1.3.5

spullen commented 11 years ago

I have it working now. I have sinatra/contrib and sinatra/config_file:

...
  register Sinatra::ConfigFile

  config_file settings.root + '/config/config.yml'
...

I commented out those two lines (the config had nothing in it anyways) and it worked. Is there a known confliction between the two libraries?

j15e commented 11 years ago

No known conflict, but seems indeed to be related and I would guess sinatra config does not set the environment variable in the way expected by sinatra/sinatra-assetpack.

j15e commented 11 years ago

Tests succeed, will be in next release, for now use edge :

gem 'sinatra-assetpack', :git => 'git://github.com/rstacruz/sinatra-assetpack.git'