【发布时间】:2016-03-14 17:10:32
【问题描述】:
我想知道何时使用 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 代码。
【问题讨论】:
标签: javascript ruby-on-rails plugins asset-pipeline precompile