自动编译资产并使用nginx(开发)为它们提供服务

vem*_*emv 10 ruby-on-rails nginx asset-pipeline

我正在开发一个拥有大量资产的Rails应用程序,但遗憾的是无法减少.在生产中,这不是问题,但在开发中,每个访问页面的约20个资产请求不能由应用程序服务器(如webrick或Thin)快速提供.

所以我开始在开发中使用nginx来提供任何服务public/assets.请注意,nginx纯粹是一个开发工具 - 我们不打算在生产中使用它.

为了它的工作,我只需要做两件事:

  • 设为config.assets.debugfalse
  • rake assets:precompile

可悲的是,我的设置存在两个问题(后者是最重要的问题):

  • 每次资产变更都需要rake assets:precompile再次手动运行
  • 为了让app服务器获取新编译的资产,我必须重新启动它.

什么是正确的nginx/Asset Pipeline设置,在预编译后不需要重新启动Rails服务器?

自动编译也是受欢迎的.

vem*_*emv 3

这个设置对我有用:

  • 包含 nginx 端口config.asset_host
  • config.assets.debug = false
  • config.assets.digest = true
  • config.assets.compile = true
  • 在启动 Rails 服务器之前,运行rm -rf public/assets; rake tmp:clear tmp:cache:clear assets:clean assets:precompile
  • 启动 Rails 服务器
  • 每次资产更改时,rake assets:precompile再次运行。警卫可以解决这个问题。