alexspeller / non-stupid-digest-assets

Fix the Rails 4 asset pipeline to generate non-digest along with digest assets
MIT License
493 stars 87 forks source link

Add info for Rails 5 / Sprockets 3 #48

Open jmarceli opened 7 years ago

jmarceli commented 7 years ago

Hi, is this gem still required for Rails 5? I didn't find any info if it is possible to compile both assets versions in Rails 5 without this gem, so I assume it is still required. It would be nice to add some info to the README.md.

georgepalmer commented 7 years ago

This fork has some Rails 5 fixes. No idea about complete compatibility but it's working how we use it

timoschilling commented 7 years ago

The changes in that fork are made by me, they are not to fix Rails 5 problems, they are just for some server setup problems.

randomizor commented 6 years ago
module NonStupidDigestAssets
  mattr_accessor :whitelist
  @@whitelist = []

  class << self
    def files(files)
      return files if whitelist.empty?
      whitelisted_files(files)
    end

    private

    def whitelisted_files(files)
      files.select do |file, info|
        whitelist.any? do |item|
          case item
          when Regexp
            info['logical_path'] =~ item
          else
            info['logical_path'] == item
          end
        end
      end
    end
  end
end

module NonDigest
  def compile *args
    super *args

    NonStupidDigestAssets.files(files).each do |(digest_path, info)|
      full_digest_path = File.join dir, digest_path
      full_digest_gz_path = "#{full_digest_path}.gz"
      full_non_digest_path = File.join dir, info['logical_path']
      full_non_digest_gz_path = "#{full_non_digest_path}.gz"

      if File.exists? full_digest_path
        # logger.info "Writing #{full_non_digest_path}"
        FileUtils.rm full_non_digest_path if File.exists? full_non_digest_path
        FileUtils.cp full_digest_path, full_non_digest_path
      else
        logger.warn "Could not find: #{full_digest_path}"
      end
      if File.exists? full_digest_gz_path
        # logger.info "Writing #{full_non_digest_gz_path}"
        FileUtils.rm full_non_digest_gz_path if File.exists? full_non_digest_gz_path
        FileUtils.cp full_digest_gz_path, full_non_digest_gz_path
      else
        logger.warn "Could not find: #{full_digest_gz_path}"
      end
    end
  end
end

module Sprockets
  class Manifest
    prepend NonDigest
  end
end
dmolesUC commented 5 years ago

Basic functionality seems fine to me in Rails 6, FWIW. What issues have other folks been seeing?

dmolesUC commented 5 years ago

OK, here's one: it looks like JS in public/packs/js doesn't get copied to the non-stupid path. Not a big deal for me as I'm only using this gem to statically link CSS and images in my 404.html and 500.html, but might be an issue for some.