rstacruz / sinatra-assetpack

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

Precompile assets errors in Sinatra before filter #158

Closed rycfung closed 10 years ago

rycfung commented 10 years ago

I'm not sure if I'm setting up this incorrectly, but when I try to precompile my assets, I'm running into issues where my compiled files are all html's. The html turns out to be the standard Sinatra error page.

It looks like parts of the precompilation consists of firing mock requests to my webapp code in order to generate those assets. Is this done intentionally? I can't imagine why my webapp needs to be fully functional in order to simply precompile javascript/css.

(looks like it's sending a mock request to the application to get the assets compiled)

      def build_get(path, &blk)
        @session ||= Rack::Test::Session.new app
        @session.get(path)
      end

This is really inconvenient when all I need are the precompiled version of the assets, but the precompile task requires my entire webapp to be functional down to the database connections it establishes when the server starts

What's the reasons behind having the assets built by calling the application with a mock request (thus requiring the application to startup along with all its dependencies)? It might be more convenient and efficient to run the actual tools like lessc and minified directly on the files, wouldn't it?

j15e commented 10 years ago

Yes this is how it is done, and yes, it is bad and cause a bunch of issues.

It would be quite a job to rewrite the compile process to skip this mocking process, I did look into doing it a long time ago, but it would require to also rewrite the underlying structure of the asset manager which rely strongly on rack routes to work properly. It would be fun to do, but I do not have enough time. Open to pull requests if you have any other workaround!