rstacruz / sinatra-assetpack

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

Unable to serve javascript from a gem in a production environment. #143

Open jasonrobertfox opened 10 years ago

jasonrobertfox commented 10 years ago

I thought I'd be clever and include the Zurb Foundation javascript files in my asset pipeline with this:

serve '/foundation', from: Foundation.js_path

And this works well in development, however when I set the environment to production I get this stack trace:

ArgumentError - comparison of NilClass with String failed:
    /Users/jfox/.rvm/gems/ruby-2.0.0-p247@sinatra-boilerplate/gems/sinatra-assetpack-0.3.1/lib/sinatra/assetpack/buster_helpers.rb:7:in `sort'
    /Users/jfox/.rvm/gems/ruby-2.0.0-p247@sinatra-boilerplate/gems/sinatra-assetpack-0.3.1/lib/sinatra/assetpack/buster_helpers.rb:7:in `cache_buster_hash'
    /Users/jfox/.rvm/gems/ruby-2.0.0-p247@sinatra-boilerplate/gems/sinatra-assetpack-0.3.1/lib/sinatra/assetpack/buster_helpers.rb:28:in `add_cache_buster'
    /Users/jfox/.rvm/gems/ruby-2.0.0-p247@sinatra-boilerplate/gems/sinatra-assetpack-0.3.1/lib/sinatra/assetpack/package.rb:73:in `production_path'
    /Users/jfox/.rvm/gems/ruby-2.0.0-p247@sinatra-boilerplate/gems/sinatra-assetpack-0.3.1/lib/sinatra/assetpack/package.rb:77:in `to_production_html'
    /Users/jfox/.rvm/gems/ruby-2.0.0-p247@sinatra-boilerplate/gems/sinatra-assetpack-0.3.1/lib/sinatra/assetpack/helpers.rb:37:in `show_one_asset_pack'
    /Users/jfox/.rvm/gems/ruby-2.0.0-p247@sinatra-boilerplate/gems/sinatra-assetpack-0.3.1/lib/sinatra/assetpack/helpers.rb:28:in `block in show_asset_pack'
    /Users/jfox/.rvm/gems/ruby-2.0.0-p247@sinatra-boilerplate/gems/sinatra-assetpack-0.3.1/lib/sinatra/assetpack/helpers.rb:27:in `map'
    /Users/jfox/.rvm/gems/ruby-2.0.0-p247@sinatra-boilerplate/gems/sinatra-assetpack-0.3.1/lib/sinatra/assetpack/helpers.rb:27:in `show_asset_pack'

...

It does not seem to like trying to serve the files from outside the app root. Is there a way to serve files directly from included gems? It seems duplicative to have to copy the zurb javascript while I can just import the scss files.

Thanks!

arman-h commented 10 years ago

I'm getting the same error. My app structure is:

/
/config.ru
/app/
/app/app.rb
/app/assets/
/app/assets/css/
/app/assets/css/style.sass
/app/assets/js/
/app/assets/js/app.js

And I'm setting it up like so:

assets do
    js_compression :jsmin
    css_compression :simple
    serve '/js', :from => 'app/assets/js'
    serve '/css', :from => 'app/assets/css'
    js :app, [
        '//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js',
        '//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js',
        '/js/app.js',
    ]
    css :style, [
        # Bootstrap
            '//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css',
        # Fonts
            '//fonts.googleapis.com/css?family=Roboto:400,500,700,900,300,100',
            '//fonts.googleapis.com/css?family=Source+Code+Pro:200,300,400,500,600,700,900',
            '//fonts.googleapis.com/css?family=Warnes',
        # Style
            '/css/style.css',
    ]
end

The error is thrown if I run the app in PRODUCTION mode only. It seems to be triggered by /js/app.js and /css/style.css. When I remove those lines from AssetPack configuration, the error dissapears.

mighe commented 10 years ago

I've just had the same problem: it happens when in the js :app or css :style param array you reference a file that does not exist.