如何在加载路径中包含供应商库?
How to include vendor library in load path?
我有一个供应商库,它有自己的目录和许多文件(js 和 css a.o)。我已将其作为文件夹放在 my_app/vendor/assets/external_library/
中。我如何引用此目录中的文件,例如在我的视图中?
例如有以下两个文件:
- my_app/vendor/assets/external_library/editor.js
- my_app/vendor/assets/external_library/contents.css
要使用这些,我添加了:
- 在application.js中:
//= require editor
- 在application.css.scss中:
@import "contents";
- 在我看来:
<script src="editor.js"></script>
它确实加载了开发中的视图页面。但是当我转到页面的源代码并单击 link 到 js 文件时,无法找到该文件。我做错了什么吗?
将此添加到您的 application.rb
文件中:
config.assets.paths << Rails.root.join('vendor', 'assets')
然后在您的 application.js 中要求这些:
//= require external_library/editor.js
和application.css.scss:
@import "external_library/contents";
在您看来,您应该只需要具备以下条件:
= stylesheet_link_tag "application", media: "all"
= javascript_include_tag "application"
我有一个供应商库,它有自己的目录和许多文件(js 和 css a.o)。我已将其作为文件夹放在 my_app/vendor/assets/external_library/
中。我如何引用此目录中的文件,例如在我的视图中?
例如有以下两个文件:
- my_app/vendor/assets/external_library/editor.js
- my_app/vendor/assets/external_library/contents.css
要使用这些,我添加了:
- 在application.js中:
//= require editor
- 在application.css.scss中:
@import "contents";
- 在我看来:
<script src="editor.js"></script>
它确实加载了开发中的视图页面。但是当我转到页面的源代码并单击 link 到 js 文件时,无法找到该文件。我做错了什么吗?
将此添加到您的 application.rb
文件中:
config.assets.paths << Rails.root.join('vendor', 'assets')
然后在您的 application.js 中要求这些:
//= require external_library/editor.js
和application.css.scss:
@import "external_library/contents";
在您看来,您应该只需要具备以下条件:
= stylesheet_link_tag "application", media: "all"
= javascript_include_tag "application"