Assets precompile missing standalone javascript / css

I have a crouching feeling that I'm missing something obvious:

I ran

RAILS_ENV=production bundle exec rake assets:precompile

to pre-assemble my assets before clicking on Heroku. It is shown in /public/assets that application.js and application.css manifest successfully compiled, but none of my offline files compiled :

 admin.js.coffee blog.js.coffee.erb [ ... several more similarly named ... ] twitter.js.coffee.erb 

and

 admin.css.less home.css.less public.css.less 

all are missing from /public/assets .

I thought that Rails would precompile application.js / .css files, as well as anything that would not end js / css:

The default compatibility for compiling files includes application.js, application.css and all files that do not end with js or css:

 [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ] 

from: http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets

I do not want to manually update config.assets.precompile every time the resource file name changes. Am I missing something that will force Rails to precompile these assets?

Update

Based on @Richard Hulse's answer below, I checked it by creating a separate manifest file for a standalone asset (i.e. I renamed twitter.js.coffee.erb to twitter-include.js.coffee.erb and added twitter.js with single //= require retraction in renamed to the original). It seems to work.

There should be a cleaner way than this , and seems to contradict the Rails tutorial above . The manual says that the only files that will not be compiled are .js or .css files that are not named application . I only see .js or .css that are directly compiled (i.e. not through the manifest) - nothing.

+6
source share
1 answer

Two things:

If these files are included in your application manifests, they are included in the site’s application files.

In both manifestations of applications, there should be a line: require_tree , which will automatically select all your assets. Is it in these files?

Edit in response to editing:

As I structured this, there are two sets of manifestations. The standard ones (application.css / .js) are publicly available. The set of administrators is for admin pages. Include all the content you want in admin.js / .css and add these files to the precompilation array:

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

This will allow you to share code between two groups. For example, you can include jquery in both, but jquery_ujs only in admin. In your admin section layout, simply include admin manifests instead of an application manifest.

In practice, you will add new files to the application or admin manifest when developing the site, and you will not have to change the configuration of the precompilation.

Once you get to adding a lot of assets, an admin section, etc., it is expected that everything will become more complex and that you should be explicit about what is included in the manifests and order (as opposed to to require_tree).

+5
source

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


All Articles