将自定义文件夹添加到 Grails 中的资产管道 [英] Adding custom folder to asset pipeline in Grails

查看:21
本文介绍了将自定义文件夹添加到 Grails 中的资产管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Grails 应用程序.我在 web-app 中有 js、css 和 image 文件夹,在同一个文件夹中我有一个主题文件夹.我打算使用资产管道插件.我应该如何使用我的主题文件夹?我在核心文件夹和主题文件夹中有同名的文件.对此有什么帮助吗?

I have a Grails application. I have the js, css and image folder in the web-app and in the same folder I have a themes folder. I am planning to use the asset pipeline plugin. How should I use my themes folder? I have files with the same names in the core folders and the themes folder. Any help on this?

推荐答案

资产管道支持自定义文件夹.我将向您展示一个使用 Bootstrap 的示例.

Custom folders are supported in the asset pipeline. I will show you an example using Bootstrap.

我们在 assets 文件夹中创建一个名为 themes 的根级目录,这是我们将存储第三方脚本的地方.您可以随意命名,例如,lib、libraries、vendor、plugins.

We create a root level directory in the assets folder called themes, this is where we will store third party scripts. You can name this anything you like, E.G., lib, libraries, vendor, plugins.

assets/
    images/
    javascript/
        application.js
    stylesheets/
        application.css
    themes/
        bootstrap/
            js/
                bootstrap.js
                bootstrap.min.js
            css/
                bootstrap.css
                bootstrap.min.css

然后您可以像这样从自定义文件夹访问这些文件:

You can then access these files from the custom folder like so:

// application.js
//= require bootstrap/js/bootstrap.js

// application.css
/*= require bootstrap/css/bootstrap.css */

// In a gsp
<asset:javascript src="bootstrap/js/bootstrap.js"/>

require 指令忽略资产文件夹中的第一个目录.这使您可以很好地模块化和组织您的资产.

The require directives ignore the first directory in the asset folder. This allows you to modularise and organise your assets nicely.

在添加新的顶级资产目录时,您可能需要重新启动 grails 应用程序.

You might need to restart your grails application when adding a new top level asset directory.

这篇关于将自定义文件夹添加到 Grails 中的资产管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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