简体   繁体   English

Rails资产管道澄清

[英]rails asset pipeline clarifications

Just a few questions to clarify some confusing factors for me. 只需提出几个问题即可为我澄清一些令人困惑的因素。

About application.js: 关于application.js:

  1. require_tree . will recursively include all the js files within app/assets/javascripts . 将以递归方式将所有js文件包含在app/assets/javascripts If I put a javascript file in app/assets/javascripts/subfolder , it will be included. 如果我将javascript文件放在app/assets/javascripts/subfolder ,它将包含在内。 If I just want to include a specific directory, I should use require_directory 如果我只想包含特定目录,则应使用require_directory
  2. lib/assets/javascripts and vendor/assets/javascripts can be referenced from the manifest, application.js . 可以从清单application.js引用lib/assets/javascriptsvendor/assets/javascripts Their javascript files WILL NOT be precompiled unless they are stated in the manifest. 除非清单中有明确说明,否则它们的javascript文件不会进行预编译。
  3. When I install a gem that requires a set of javascripts(eg bootstrap) I require the related javascripts files in the manifest too (eg //= require bootstrap ). 当我安装需要一组javascripts(例如bootstrap)的gem时,我也需要清单中的相关javascripts文件(例如//= require bootstrap )。 The javascript files live in the Gem path, and they can be referenced by relative paths too. javascript文件位于Gem路径中,它们也可以由相对路径引用。

Are my statements all true? 我的陈述全部正确吗?

For sure I can say that 1 & 3 are true, I use both of those statements in my code. 可以肯定地说1和3是正确的,我在代码中同时使用了这两个语句。 When it comes to numer 2, as Rails Asset Pipeline docs says: 关于数字2,正如Rails Asset Pipeline文档所说:

For example, these files: 例如,这些文件:

  app/assets/javascripts/home.js lib/assets/javascripts/moovinator.js vendor/assets/javascripts/slider.js 

would be referenced in a manifest like this: 将在清单中引用如下:

  //= require home //= require moovinator //= require slider 

http://guides.rubyonrails.org/asset_pipeline.html#asset-organization http://guides.rubyonrails.org/asset_pipeline.html#asset-organization

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM