【问题标题】:Ruby Rails precompiling assets vs. using the asset pipelineRuby Rails 预编译资产与使用资产管道
【发布时间】: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


    【解决方案1】:

    我在这个网站上找到了我自己问题的答案:https://launchschool.com/blog/rails-asset-pipeline-best-practices。基本上,答案是肯定的,我的理解是正确的。

    以下是文章的相关部分:

    【讨论】:

      猜你喜欢
      • 2013-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-20
      • 2012-10-01
      • 2012-03-19
      相关资源
      最近更新 更多