How do I use config.assets.precompile for directories rather than single files?

前端 未结 5 1704
情书的邮戳
情书的邮戳 2021-01-01 18:34

How do I use config.assets.precompile in production to only include the files in \'lib/assets/javascripts\', \'lib/assets/stylesheets\', \'vendor/assets/javascripts\' and \'

5条回答
  •  别那么骄傲
    2021-01-01 19:11

    I found this link, and think may be it helpful for you, please see

    keithgaputis's answer. Rails config.assets.precompile setting to process all CSS and JS files in app/assets

    I think you can do like following.

    # In production.rb
    config.assets.precompile << Proc.new { |path|
      if path =~ /\.(css|js)\z/
        full_path = Rails.application.assets.resolve(path).to_path
        app_assets_path = Rails.root.join('app', 'assets').to_path
        if full_path.starts_with? app_assets_path
          puts "excluding asset: " + full_path
          false
        else
          puts "including asset: " + full_path
          true
        end
      else
        false
      end
    }
    

提交回复
热议问题