Asset precompilation woes#53
Asset precompilation woes#53RISCfuture merged 1 commit intoSquareSquash:masterfrom bjeanes:precompile-all-assets-in-all-envs
Conversation
|
Seems like option 2 would be out: |
|
Unless I'm mistaken, option 2 restricts the flexibility of people's deploy situations. Some people will want to precompile their assets locally, and others will want to do it on the target. And no matter what environments |
|
Makes sense... that's what I did locally too, so I'm glad you agree. I'll send a PR shortly. |
|
@RISCfuture I just added a commit that solves the issue for me locally and allows me to run |
|
Note, this is also breaking deploys on heroku. For heroku, we need to either compile localy or set config.assets.initialize_on_precompile = false. Plus IMHO, for deploy, it shouldn't be mandatory to setup and run the app on development. |
|
@gamafranco actually, for Heroku I believe you can also follow https://devcenter.heroku.com/articles/labs-user-env-compile to have it "just work" |
|
Hi bjeanes, Thanks for the tip, I don't see how that might help. Heroku dones't allow database connections at asset compile time, so config.assets.initialize_on_precompile needs to be false. And that raises the problems you identified above. Thanks. |
|
@gamafranco it will help because that's the point of that lab feature. It will provide the database details at "compilation" time such that your rake task will know which database to connect to. Search that page for "assets:precompile" |
|
@RISCfuture bump. Commit attached that solves problem using method 1. |
…-in-all-envs Asset precompilation woes
Currently
config.assets.initialize_on_precompileis set to true (the default). This means, if you want to precompile assets prior to a deployment (e.g. creating a war file, deploying to Heroku, or just doing the work once before sending out to many servers), you need to have access to the production DB.Usually, to counter this, one can set
RAILS_ENV=developmentbefore running the precompilation rake task. However, in the case of Squash, "flot/excanvas.js" is added toconfig.assets.precompileonly inconfig/environments/production.rbresulting in aActionView::Template::Error (flot/excanvas.js isn't precompiled)error at runtime in production.So, there are two ways out of this that I see. I'm happy to issue a pull request for either direction, I just wanted some input first in case there is a preferred route:
config.assets.precompile << 'flot/excanvas.jsfromproduction.rbtoapplication.rbso it is effective in all compilation environments (i.e. allowing precompilation withRAILS_ENV=development)config.assets.initialize_on_precompile = falseso that a DB connection is not formed. This has other issues if any of the assets access certain classes or constants at compile time (e.g. ERB assets).For option 2, one error that already pops up is
uninitialized constant Pingdue to a lot of assumedrequires not happening. Things like this would need to be resolved.