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

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

问题描述

我有一个Grails应用程序。我有Web应用程序中的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.

我们在名为themes的资产文件夹中创建一个根级目录,这是我们将存储第三方脚本的地方。您可以将您喜欢的任何名称命名为EG,lib,库,供应商,插件。

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天全站免登陆