Rails: exclude pre-compilation of certain assets

What I want is very simple - I want all assets except a specific css file (which refers to image objects and therefore must go through the asset pipeline) must be precompiled. How can I rule out that the css file was precompiled?

+4
source share
2 answers

There are several possible answers, depending on what you want. I do not quite understand what you are asking.

If it's in the app / assets, you really need something there to go through the asset pipeline in order to be accessible. In production, you need to pre-assemble all your assets that are part of the asset market and, if necessary, recompile them in production mode.

If the asset name does not have the scss or sass , it will not go through the scss / sass compiler, although it will still go through the asset pipeline for the fingerprints in the file name, gzipping, etc.

If you really do not want any asset to go through the asset pipeline, you cannot put it in app/assets . You must put it in public . Then the question arises, how to generate the URL, it is best to use public_path + "/subdir/foo.css" .

But I'm not sure what you are asking. If you have an asset file that refers to an image path, usually you need this through the asset pipeline, absolutely! Because it is an asset pipeline that will correctly fill in the URLs for these image assets. You will want to use the Rails attribute helper in the asset file to create the URL for the image. You can put .erb at the end of the file and then use the ERB codes <%= asset_path('my_asset.css') %> in it it. Or if it sass, <%= asset_path('my_asset.css') %> in it it. Or if it sass, asset_path` can be built into rails sass already, I forgot.

I don’t quite understand what the problem is that you are facing, but I think that what you are asking for may actually not be what you need. Have you checked the Rails Asset Pipeline manual? This is pretty decent. http://guides.rubyonrails.org/asset_pipeline.html

0
source

Looks like you really want the file to be precompiled separately from other files?

If you just need to add it to the Rails.application.config.assets.precompile array. See config/initializers/assets.rb for a commented line as an example.

0
source

Source: https://habr.com/ru/post/1411141/


All Articles