轨道 3 和开发/生产模式下的资产管道
在生产服务器上预编译资产非常慢。因此,我决定在开发机器上重新编译它们,并通过 jammit
将资源上传到 Amazon S3。一切都完成了,但我有一些负面问题:
- 我必须将
public/assets
目录包含到git
控制中。因为如果生产服务器上的public/assets
目录为空,则会失败 - 如果我在开发计算机上预编译资产
application.js
包含在压缩的 HTML 中,这样我就复制了js 代码。更改 js 不会产生任何效果,因为预编译的application.js
会中断此代码。
这样,我的开发过程包括以下步骤:
- 如果我要更改 js 或 css,则删除预编译资产
- 进行一些更改
- 预编译资产
- 通过
jammit-s3
将资产上传到 S3 - 提交并推送我的更改(包括资产)到 git 服务器
- 由 capistrano 部署
我的问题是:
- 如果我将压缩的
application.js
放在public/assets
目录中,是否可以配置开发环境不包含压缩的application.js
? - 是否可以将生产环境配置为使用空的
public/assets
目录?资产仅位于 S3 服务器上。
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
. Everything's done but I have some negative problems:
- I have to include
public/assets
directory togit
control. Because ifpublic/assets
directory is empty on the production server fails - If I precompile assets on the development machine
application.js
includes in the HTML as compressed and that way I have duplicated js code. Changing js doesn't make any effect because precompiledapplication.js
interrupts this code.
That way my development process includes following steps:
- Remove precompiled assets if I'm going to change js or css
- Do some changes
- Precompile assets
- Upload assets to S3 by
jammit-s3
- Do commit and push my changes including assets to the git server
- Deploy by capistrano
My questions are:
- Is it possible to configure development environment don't include compressed
application.js
if I have it inpublic/assets
directory? - Is it possible to configure production environment to work with empty
public/assets
directory? Assets will only be on the S3 server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于问题一,我不知道除了运行之外的永久解决方案:
在切换回开发模式之前。我很想知道您是否可以忽略正在开发的资产而不关闭整个资产管道。
在 Production.rb 中,有一个选项可以解决您的第二个问题:
然后它应该忽略您的资产目录,因为它依赖于远程主机。
希望有帮助。
For question one I don't know a permanent solution other than running:
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:
It should then ignore your assets directory since it relies on the remote host.
Hope that helps.
我通过在 gitignore 中包含资产目录并仅排除一个文件 -
public/assets/manifest.yml
解决了这个问题,并且生产服务器现在可以正常工作,即config.action_controller.asset_host = "http: //assets.example.com"
有效。它只需要manifest.yml
文件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, i.e.config.action_controller.asset_host = "http://assets.example.com"
works. It requires onlymanifest.yml
file