Rails 3.1 Asset Pipeline 清单文件不会获取 javascript

发布于 2024-12-26 15:39:41 字数 332 浏览 3 评论 0原文

我在vendor/assets/javascripts中有一大堆乱七八糟的javascripts。在我的 app/assets/javascripts/application.js 文件中,我有指令:

//= require_tree .

是否仅引用当前的 app/assets/javascripts 目录,而不引用 lib/assets 或vendor/assets?

如果我明确包含 JavaScript,它就可以工作。如果不需要的话我真的不想这么做。

我是否缺少一些东西,可以让资产管道能够自动从应用程序目录(lib 和供应商)外部提供资产?

I have a whole MESS of javascripts in vendor/assets/javascripts. In my app/assets/javascripts/application.js file, I have the directive:

//= require_tree .

Does that only reference the current app/assets/javascripts directory, and not lib/assets or vendor/assets?

If I explicitly include the javascripts, it works. I just don't really want to do that if I don't have to.

Is there something I am missing that will allow the assets pipeline to be able to serve up assets from outside the app directory (lib and vendor) automatically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烛影斜 2025-01-02 15:39:41

require_tree 仅提取 application.js 文件下的资源。

lib/assetsvendor/assets 已包含在管道的查找路径中 (参考此代码)。

您可以使用第二个清单包含这些供应商的文件。

转到vendor/assets/javascripts并创建一个名为misc_vendor.js的文件

,在其中添加一个require_tree指令。

然后从您的 application.js 清单中引用该文件:

require misc_vendor

如果您因加载顺序而遇到任何问题,您可以按照您需要的顺序手动请求供应商文件,而不是使用 require_tree。

作为管道转换的一部分,这可能是清理东西的好机会! :-)

require_tree only pulls in assets that are under the application.js file.

lib/assets and vendor/assets are already included in the lookup paths for the pipeline (refer this code).

You can include these vendored files by using a second manifest.

Go to vendor/assets/javascripts and create a file called misc_vendor.js

Inside that add put a require_tree directive.

Then refer to that file from your application.js manifest:

require misc_vendor

If you have any issues because of loading order you can manually require the vendor files in the order you need instead of using require_tree.

As part of the conversion to the pipeline it may be a good chance to clean up things! :-)

烂人 2025-01-02 15:39:41

另外,您可以在没有第二个清单的情况下执行此操作,如下所示:

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

路径应相对于“app/assets/javascripts/application.js”清单文件。

Also, you can do it without a second manifest like this:

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

The path should be relative to the 'app/assets/javascripts/application.js' manifest file.

你对谁都笑 2025-01-02 15:39:41

您需要像这样扩展 application.rb 文件中的路径。

config.assets.paths << "#{Rails.root}/vendor/assets/some file name"

请参阅本指南了解更多详细信息

You need to extend path in application.rb file like this.

config.assets.paths << "#{Rails.root}/vendor/assets/some file name"

Refer this Guide for more details

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文