且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将自定义文件夹添加到 Grails 中的资产管道

更新时间:2022-12-11 16:51:27

资产管道支持自定义文件夹.我将向您展示一个使用 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.