Rails递归地包含javascripts资源文件夹

时间:2022-05-04 00:26:47

I understand how to add one javascript file to rails assets pipeline. Just add

我理解如何将一个javascript文件添加到rails资产管道。只需添加

//= require filename 

to application.js

到application.js

But how can I include many javscripts files under one folder

但是如何在一个文件夹下包含许多javscripts文件

vendor/assets/javascripts/<js_library>

Or I have to list them all explicitly ?

或者我必须明确地列出它们?

1 个解决方案

#1


40  

//= require_tree .

will require everything in the current directory of your application.js

将需要application.js的当前目录中的所有内容

//= require_tree ./js_library

will require everything in the js_library subdirectory if it is under app/assets/javascripts

如果它位于app / assets / javascripts下,则需要js_library子目录中的所有内容

If you are are trying to load javascripts under vendor/assets/javascripts, try:

如果您正在尝试在vendor / assets / javascripts下加载javascripts,请尝试:

//= require_tree ../../../vendor/assets/javascripts/js_library

#1


40  

//= require_tree .

will require everything in the current directory of your application.js

将需要application.js的当前目录中的所有内容

//= require_tree ./js_library

will require everything in the js_library subdirectory if it is under app/assets/javascripts

如果它位于app / assets / javascripts下,则需要js_library子目录中的所有内容

If you are are trying to load javascripts under vendor/assets/javascripts, try:

如果您正在尝试在vendor / assets / javascripts下加载javascripts,请尝试:

//= require_tree ../../../vendor/assets/javascripts/js_library