Grails 资源插件并根据环境使用不同的资源

标签 grails resources minify

在我当前的 grails 项目中,我们正在使用 UglifyJS 缩小 JavaScript 文件,并在开发环境中使用这些缩小后的资源。正如您可以想象的那样,在缩小版本上进行调试有点麻烦,修复未缩小版本中的错误,缩小它并再次调试。因此,我想在开发环境中包含未缩小的版本,在生产中包含缩小的版本。所以我尝试调整 ApplicationResources.groovy 以获得以下方案:

environments {
    development {
        modules = {
            core {
                resource url:"js/core.js"
            }
        }
    }
    production {
        modules = {
            core {
                resource url:"js/core.min.js"
            }
        }
    }
}

这在某种程度上不起作用,并且会抛出异常,例如

Caused by GrailsTagException: Error executing tag <r:layoutResources>: No module found with name [core]

我在这里做错了什么?

更新:

我不确定我是否正确理解了这一点。我尝试了以下方法,但也不起作用:

更新:

添加 ids 就可以了:)

ApplicationResources.groovy

modules = {
    core {
        resource id: 'core', url:"js/core.min.js"
    }
}

DevelopmentResources.groovy

environment {
    development {
        modules = {
            overrides {
                core {
                    resource id: 'core', url:"js/core.js"
                }
            }
        }
    }
}

最佳答案

尝试在单独的文件中定义 dev 和 prod 资源模块。例如 StaticResources.groovy 和 ProductionResources.groovy。

Each Resources file ultimately provides Grails with one "modules" closure, Grails then combines the definitions from the closures provided by each file to produce the final configuration.

这是complete nabble discussion .

关于Grails 资源插件并根据环境使用不同的资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15009767/

相关文章:

macos - 通过Brew重新启动终端安装Grails Mac OSX

c++ - 使用资源文件进行 C++ 编译时出错

asp.net - 缩小 ASP.NET 应用程序的 Html 输出

mysql - 在grails应用程序中执行MySQL脚本

grails 数据绑定(bind)集合

grails - 查找今天更新的域实例

android - ListView/GridView 中按下项目的默认背景颜色

wpf - 如何重用 WPF DataGridTemplateColumn(包括绑定(bind))

javascript - 将 Google Firebase 应用程序部署与 Aurelia 结合使用,您如何仅设置和部署打包 Assets ?

javascript - 使用 TSQL 到 "minify"javascript 代码?