1

我正在使用 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"]
                    }
                ]
            }

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

4

1 回答 1

4

As best I can tell, Grunt does not expand patterns in cwd, so your option

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

never gets converted to an array of matching directories.

You can follow my logic for this conclusion by starting at this line in the source. grunt.file.expandMapping (source here) doesn't call grunt.file.expand on your cwd pattern.

That doesn't mean you can't do it yourself. I've used the following pattern to accomplish something similar with grunt-contrib-sass when I have sass files spread out over several directories:

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"]
            };
        }),
    }
于 2014-08-01T13:11:12.410 回答