Rails Rails 静态资源编译

rails_taotao · April 23, 2018 · Last by rails_taotao replied at April 27, 2018 · 2158 hits

请教各位技术大佬。rails 在部署的时候,会编译静态资源。这个时候特别占用内存与时间。有没有可以实现开发环境将静态资源编译好,在部署的过程中不参加编译静态资源。生产环境使用开发环境编译过的静态资源。

在开发的机器上预编译就行了:

RAILS_ENV=production rails assets:precompile

把生成的文件提交到代码仓库中,生产环境直接更新代码即可。

楼上正解

如果是用 capistrano 部署的话 记得在 Capfile 里把 precompile 拿掉

Reply to jicheng1014

我是使用 mina+unicon 进行部署的

或者采用本地编译,上传

gem 'capistrano-local-precompile'
Reply to awking

谢谢分享

是不是每次部署后,第一次访问页面是要加载半天?

Reply to lengcb

是的。而已编译的过程很长

Reply to junzhepan

你好,我这样测试过,但是没有成功。我是使用 mina 进行部署的

Reply to junzhepan

这样会不会导致项目文件太大呢?

Reply to lengcb

我今天这样尝试了。系统一直报错。还没有解决。

要解决每次部署编译 js 时间太长,linked_dirs 可以加上

['tmp/cache','public/assets']
Reply to zqalyc

已经解决。谢谢

rails_taotao closed this topic. 27 Apr 09:07
You need to Sign in before reply, if you don't have an account, please Sign up first.