LoginSignup
3
1

More than 5 years have passed since last update.

ローカル環境でasset_syncを発動させたくない

Last updated at Posted at 2018-10-05

assets:precompileしたら、クラウド上のストレージに画像とか自動でアップロードしてくれる便利な asset_sync
これローカル環境でも実行されてしまうんですよね。ローカル用のS3のバケットとか用意してるのなら別ですけど、特に必要ないなら実行しないで欲しいですよね。

その設定がちゃんとREADMEに書いてあったので、メモしておきます。

TL;DR

config/initializers/asset_sync.rb
AssetSync.configure do |config|
  config.enabled = false if Rails.env.development? # ここを追記
  config.fog_provider = 'AWS'
  config.fog_directory = ENV['FOG_DIRECTORY']
  config.fog_region = ENV['FOG_REGION']
  config.aws_iam_roles = true
  config.manifest = true
end

config.enabled オプションはデフォルトで true になっているので、 development環境の場合だけ、 false にするようにしてあげればOKです。かんたん!

以下READMEを引用しますが、太字の部分がその設定値ですね。
https://github.com/AssetSync/asset_sync#assetsync-optional

AssetSync (optional)

  • existing_remote_files: ('keep', 'delete', 'ignore') what to do with previously precompiled files. default: 'keep'
  • gzip_compression: (true, false) when enabled, will automatically replace files that have a gzip compressed equivalent with the compressed version. default: 'false'
  • manifest: (true, false) when enabled, will use the manifest.yml generated by Rails to get the list of local files to upload. experimental. default: 'false'
  • include_manifest: (true, false) when enabled, will upload the manifest.yml generated by Rails. default: 'false'
  • enabled: (true, false) when false, will disable asset sync. default: 'true' (enabled)
  • ignored_files: an array of files to ignore e.g. ['ignore_me.js', %r(ignore_some/\d{32}.css)] Useful if there are some files that are created dynamically on the server and you don't want to upload on deploy default: []
  • cache_asset_regexps: an array of files to add cache headers e.g. ['cache_me.js', %r(cache_some.\d{8}.css)] Useful if there are some files that are added to sprockets assets list and need to be set as 'Cacheable' on uploaded server. Only rails compiled regexp is matched internally default: []
3
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1