简体   繁体   English

Rails 3和资产管道处于开发/生产模式

[英]Rails 3 & assets pipeline in development/production mode

Precompiling assets on the production server is very slow. 在生产服务器上预编译资产非常慢。 So I have decided to recompile them on the development machine and upload assets to the Amazon S3 by jammit . 所以我决定在开发机器上重新编译它们,并通过jammit将资源上传到Amazon S3。 Everything's done but I have some negative problems: 一切都完成了,但是我有一些负面问题:

  1. I have to include public/assets directory to git control. 我必须将public/assets目录包含在git控件中。 Because if public/assets directory is empty on the production server fails 因为如果生产服务器上的public/assets目录为空,则失败
  2. If I precompile assets on the development machine application.js includes in the HTML as compressed and that way I have duplicated js code. 如果我在开发机器上预编译资源application.js包含在HTML中作为压缩,那么我有重复的js代码。 Changing js doesn't make any effect because precompiled application.js interrupts this code. 更改js不会产生任何影响,因为预编译的application.js中断此代码。

That way my development process includes following steps: 这样我的开发过程包括以下步骤:

  1. Remove precompiled assets if I'm going to change js or css 如果我要更改js或css,请删除预编译的资产
  2. Do some changes 做一些改变
  3. Precompile assets 预编译资产
  4. Upload assets to S3 by jammit-s3 通过jammit-s3资源上传到S3
  5. Do commit and push my changes including assets to the git server 提交并将我的更改(包括资产)推送到git服务器
  6. Deploy by capistrano 由capistrano部署

My questions are: 我的问题是:

  1. Is it possible to configure development environment don't include compressed application.js if I have it in public/assets directory? 是否有可能配置开发环境不包括压缩的application.js如果我在public/assets目录中有它?
  2. Is it possible to configure production environment to work with empty public/assets directory? 是否可以配置生产环境以使用空的public/assets目录? Assets will only be on the S3 server. 资产只能在S3服务器上。

For question one I don't know a permanent solution other than running: 对于问题一,我不知道除了运行之外的永久解决方案:

bundle exec rake assets:clean

before you switch back to development mode. 在切换回开发模式之前。 I'd be interested to see if you can just ignore the assets in development without turning the entire assets pipeline off. 我很想知道您是否可以在不关闭整个资产管道的情况下忽略开发中的资产。

In production.rb there is an option for your second question: 在production.rb中,您可以选择第二个问题:

# Enable serving of images, stylesheets, and JavaScripts from an asset server
config.action_controller.asset_host = "http://assets.example.com"

It should then ignore your assets directory since it relies on the remote host. 然后它应该忽略您的资产目录,因为它依赖于远程主机。 Hope that helps. 希望有所帮助。

I resolved this problem by including assets dir in gitignore and exclude only one file - public/assets/manifest.yml and production server works correctly now, ie config.action_controller.asset_host = "http://assets.example.com" works. 我通过在gitignore中包含资产目录来解决此问题,并且仅排除了一个文件-public public/assets/manifest.yml和生产服务器现在可以正常工作,即config.action_controller.asset_host = "http://assets.example.com"可以工作。 It requires only manifest.yml file 它只需要manifest.yml文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM