1

I've seen a few questions/answers around avoiding precompiling various assets while using the Rails pipeline; however, I want to effectively blacklist via an array of Regex's for pathname matches to exclude from precompilation. Most often for me, this is often a set of partials that will fail precompilation anyway.

1 Answer 1

1

First off -- keithgaputis has expertly answered a part of this here but it's not quite an answer to the above question. Read and vote up his answer and then see my additions to his below:

Rails.application.config.assets.precompile << Proc.new { |path|
        blacklist = [
                /nvd3\/src\/intro.js$/,
                /nvd3\/src\/outro.js$/,
                /^.*\.less$/,
                /admin\/modules/,
                /admin\/themes/,
                /admin\/responsive\..*css/
        ]
        full_path = Rails.application.assets.resolve(path)#.to_path
        puts "path: #{path}\nfull_path: #{full_path}" if BLACK_MAGIC[:assets][:debug]

        if (path =~ /(^[^_\/]|\/[^_])[^\/]*$/) and (path !~ Regexp.union(blacklist) )

                puts "including asset: " + full_path if BLACK_MAGIC[:assets][:debug]
                true
        else
                puts "excluding asset: " + full_path if BLACK_MAGIC[:assets][:debug]
                false
        end
}

You can add all of your regular expressions to the blacklist array for exclusion and then the two part if condition

if (path =~ /(^[^_\/]|\/[^_])[^\/]*$/) and (path !~ Regexp.union(blacklist) )

will first eliminate items beginning with underscore (this isn't quite a perfect Regex yet, play with rubular) and secondly will eliminate anything that matches the blacklisted expressions. Happy coding!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.