Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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.</p> <p>Suppose my project has the JS file "/app/assets/javascripts/foo/bar.js.coffee".</p> <p>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.</p> <p>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. </p> <p>Here is the solution that I am using. I am fairly new to Ruby so this is not the most elegant code:</p> <pre><code># In production.rb config.assets.precompile &lt;&lt; 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 } </code></pre> <hr> <p>With sprockets > 3.0, this will not work in production because Rails.application.assets will be nil (assuming default: config.assets.compile = false). </p> <p>To workaround you replace the <strong>full_path</strong> assignment with:</p> <pre><code>@assets ||= Rails.application.assets || Sprockets::Railtie.build_environment(Rails.application) full_path = @assets.resolve(path) </code></pre> <p>See also: <a href="https://github.com/rails/sprockets-rails/issues/237" rel="nofollow">https://github.com/rails/sprockets-rails/issues/237</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload