Home > Back-end >  Print the names of all assets in the Asset Pipeline?
Print the names of all assets in the Asset Pipeline?

Time:10-15

I'm trying to debug why some assets are found and others not in the Asset Pipeline. i've tried a lot of obvious things (like typos, clearing tmp, clean/clobber).

Now I placed binding.pry right before where the image path is generated, and I'd like to view (print to the rails console / debugger) the name of every asset rails thinks is available.

How can I do that?

CodePudding user response:

You can take a look at the manifest:

Rails.application.assets_manifest

# or just the files 
# this is empty in some of my apps, no idea why, maybe cache or some 
# lazy loading that I'm missing:

Rails.application.assets_manifest.assets

Or maybe loop through asset paths:

Rails.configuration.assets.paths.flat_map{ |path| Dir.glob("#{path}/*.{js,css}") }

CodePudding user response:

Please note, this doesn't answer the question (how to view the available assets in the console/debugger), and therefore shall not be accepted as an answer, but it's a small start: showing how to view assets from the terminal:

rails webpacker:clean
rails webpacker:clobber
rails webpacker:compile 

The last step will print all the available assets to the terminal.

Another way is to run bin/webpack from the terminal, and in the output will be each asset. Again, this doesn't provide the list from the console or debugger.

  • Related