如何在Rails 4中加载供应商资产文件夹? [英] How to load vendor asset folder in Rails 4?

查看:94
本文介绍了如何在Rails 4中加载供应商资产文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个插件,其中包含许多类型的文件,并且具有自己的树结构(html,css,js,文档,图像等)

I have a plugin with many types of files, and its own tree structure (html, css, js, documentation, images, etc)

我不想遍历plugin文件夹,而是将所有的css和js文件拆分为vendor/assets/js/ vendor/assets/css/文件夹,而只是保留整个plugin文件夹.例如

Rather than going through the plugin folder, and splitting all the css and js files into the vendor/assets/js/ vendor/assets/css/ folders, I want to just keep the entire plugin folder as is. For example,

vendor/assets/multipurpose_bookshelf_slider/

如何确保路径正确加载,并在清单文件中引用它们?

How do I make sure the paths load properly, and reference them in my manifest files?

当前,我有一些文件放置如下(并非详尽无遗)

Currently, I have some files place as follows (not exhaustive)

/my_app/vendor/assets/multipurpose_bookshelf_slider/css/skin01.css
/my_app/vendor/assets/multipurpose_bookshelf_slider/js/jquery.easing.1.3.js
/my_app/vendor/assets/multipurpose_bookshelf_slider/
/my_app/vendor/assets/multipurpose_bookshelf_slider/

我在

application.js

//= require multipurpose_bookshelf_slider/js/jquery.easing.1.3.js
//= require multipurpose_bookshelf_slider/js/jquery.bookshelfslider.min.js

application.css.scss

@import "css/bookshelf_slider";
@import "css/skin01";

推荐答案

直接在assets下创建的任何文件夹都将添加到加载路径.可以像往常一样引用该文件夹中的文件:

Any folder created directly under assets will be added to the load paths. Files in that folder can be referenced as usual like so:

如果有

  • vendor/assets/custom/js/file.js

vendor/assets/custom/css/file.css

然后vendor/assets/custom/将被添加到加载路径.

then vendor/assets/custom/ will be added to the load paths.

通过执行以下操作,将文件包括在以下文件中:

Include your files in the following files by doing the following:

application.js

//= require js/file

application.css.scss

@import "css/file";

完成后,请确保重新启动本地服务器,因为只有在启动服务器时,负载路径才会被识别.

Once that's done, make sure to restart your local server, since it is upon starting your server that the load paths get recognized.

注意:要查看加载路径列表,请在终端rails c中键入,然后键入Rails.application.config.assets.paths.

Note: to see a list of load paths, type in your terminal rails c, then type Rails.application.config.assets.paths.

这篇关于如何在Rails 4中加载供应商资产文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆