Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7780413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:53:23+00:00 2026-06-01T18:53:23+00:00

I wish to precompile all the CSS and JS files in my project’s app/assets

  • 0

I wish to precompile all the CSS and JS files in my project’s app/assets folder. I do NOT want to precompile everything in vendor/assets or lib/assets, only the dependencies of my files as needed.

I tried the following wildcard setting, but it incorrectly precompiles everything. This results in lots of extra work and even causes a compilation failure when using bootstrap-sass.

config.assets.precompile += ['*.js', '*.css']

What is my best bet to only process my files in app/assets? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:53:25+00:00Added an answer on June 1, 2026 at 6:53 pm

    This task is made more difficult by the fact that sprockets works with logical paths that do not include where the underlying, uncompiled resourced is located.

    Suppose my project has the JS file “/app/assets/javascripts/foo/bar.js.coffee”.

    The sprockets compiler will first determine the output file extension, in this case “.js”, and then the evaluate whether or not to compile the logical path “foo/bar.js”. The uncompiled resource could be in “app/assets/javascripts”, “vendor/assets/javascripts”, “lib/assets/javascripts” or a gem, so there is no way to include/exclude a particular file based on the logical path alone.

    To determine where the underlying resource is located, I believe it is necessary to ask the sprockets environment (available via the object Rails.application.assets) to resolve the real path of the resource given the logical path.

    Here is the solution that I am using. I am fairly new to Ruby so this is not the most elegant code:

    # 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 "including asset: " + full_path
          true
        else
          puts "excluding asset: " + full_path
          false
        end
      else
        false
      end
    }
    

    With sprockets > 3.0, this will not work in production because Rails.application.assets will be nil (assuming default: config.assets.compile = false).

    To workaround you replace the full_path assignment with:

    @assets ||= Rails.application.assets || Sprockets::Railtie.build_environment(Rails.application)
    full_path = @assets.resolve(path)
    

    See also: https://github.com/rails/sprockets-rails/issues/237

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wish to get a list of all strings that are used in a
I wish to draw circle but when I fill() my arc all other shapes
I wish to contribute code to http://svn.r-project.org/R/ But I only have experience with using
... wish all of you are having a nice Valentine's Day .. For me,
I wish to track all http packets going out and comming in to the
I wish to use leveldb in my pure C# project. I have googled for
I wish to know all the pros and cons about using these two methods.
I wish I were a CSS smarty .... How can you place a div
Wish you all are doing fine at the start of a new year I
I wish to use Google organisational chart within my ASP.NET MVC project. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.