簡體   English   中英

Ruby Rails預編譯資產與使用資產管道

[英]Ruby Rails precompiling assets vs. using the asset pipeline

我想知道何時使用Rails.application.config.assets.precompile包括Javascript插件,何時使用資產管道。 據我了解,資產管道會縮小其中列出的所有文件,並使此縮小的文件可用於整個應用程序。 但是,您可以在config / initializers / assets.rb中使用Rails.application.config.assets.precompile允許插件僅在特定頁面上使用。 這種理解正確嗎?

例如,如果我的config / initializers / assets.rb文件中包含以下幾行

Rails.application.config.assets.precompile += %w( plugins/footable/angular-footable.js )
Rails.application.config.assets.precompile += %w( plugins/footable/footable.all.min.js )
Rails.application.config.assets.precompile += %w( plugins/footable/footable.core.css )

然后,我可以在我的app / views / users / index.html.erb文件中使用Foo Table插件:

<%= javascript_include_tag 'plugins/footable/angular-footable' %>
<%= javascript_include_tag 'plugins/footable/footable.all.min' %>
<%= stylesheet_link_tag 'plugins/footable/footable.core' %>

這是正確的用法嗎?

我問的原因是因為我只想在app / views / users / index.html.erb頁面上使用Foo Table插件(以及其他)。 我曾考慮將插件包含在資產管道中,但我不想讓我的應用程序其余部分陷入僵局,而Javascript代碼只需要一頁即可。

我在以下網站上找到了自己的問題的答案: https : //launchschool.com/blog/rails-asset-pipeline-best-practices 基本上,答案是肯定的,我的理解是正確的。

這是文章的相關部分: 在此處輸入圖片說明

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM