apistrano-faster-assets插件爲普通的Rails資產提供了這種功能。
您可能需要檢查core task to see how that's done並修改或複製粘貼代碼以供使用。
這裏是我的嘗試只提取相關的步驟,並提供一些更多的評論:
class PrecompileRequired < StandardError; end
begin
# get the previous release
latest_release = capture(:ls, '-xr', releases_path).split[1]
# precompile if this is the first deploy
raise PrecompileRequired unless latest_release
# create a 'Pathname' object for latest_relase
latest_release_path = releases_path.join(latest_release)
# execute raises if there is a diff
execute(:diff, '-Naur', release_path.join('path/to/frontend/code'), latest_release_path.join('path/to/frontend/code')) rescue raise(PrecompileRequired)
info("Skipping asset precompile, no asset diff found")
# copy over all of the assets from the last release
execute(:cp, '-r', latest_release_path.join('public', fetch(:assets_prefix)), release_path.join('public', fetch(:assets_prefix)))
rescue PrecompileRequired
# execute compile command here
end