【问题标题】:Grunt JS file pattern in cwdcwd 中的 Grunt JS 文件模式
【发布时间】:2014-07-29 20:49:38
【问题描述】:

我正在使用 grunt 构建我的项目并具有以下 src 结构:

app/src/client/pages/user/users.js
app/src/client/pages/user/users.html

app/src/client/pages/project/projects.js
app/src/client/pages/user/projects.html

现在,我正在尝试将我的项目构建为如下所示:

app/dist/client/users.html

我使用 contrib-htmlmin 插件,我的 grunt 配置如下所示:

htmlmin: {
            options: {
                    removeComments: true,
                    collapseWhitespace: true
            },      
            partials: {
                files: [
                    {
                        expand: true,
                        cwd: "app/src/client/pages/*/",
                        dest: "app/dist/client/",
                        src: ["*.html"]
                    }
                ]
            }

但这根本不起作用,没有文件被缩小。 有什么建议吗?

【问题讨论】:

    标签: build gruntjs cwd


    【解决方案1】:

    据我所知,Grunt 不会扩展 cwd 中的模式,所以您可以选择

    cwd: "app/src/client/pages/*/",
    

    永远不会转换为匹配目录的数组。

    您可以按照我的逻辑从at this line in the source 开始得出这个结论。 grunt.file.expandMapping (source here) 不会在您的 cwd 模式上调用 grunt.file.expand

    这并不意味着你不能自己做。当我的 sass 文件分布在多个目录中时,我使用以下模式完成了与 grunt-contrib-sass 类似的操作:

    htmlmin: {
        options: {
                removeComments: true,
                collapseWhitespace: true
        },      
        partials: {
            files: grunt.file.expand(['app/src/client/pages/*/']).map(function(cwd) {
                return {
                    expand: true,
                    cwd: cwd,
                    dest: "app/dist/client/",
                    src: ["*.html"]
                };
            }),
        }
    

    【讨论】:

    • 为什么文档中没有这个例子?它为我节省了大量时间。
    猜你喜欢
    • 1970-01-01
    • 2015-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多