省略了 Grunt 配置函数

Grunt config functions omitted

我试图在 useminPrepare 配置中定义一个自定义函数,但无论我做什么,该函数最终都在构建中被省略了。

我已将 Node(0.10.36) 和 NPM(2.4.1) 更新到最新版本。

配置文件:

useminPrepare: {
    src: options.dist.dir + '/index.html',
    options: {
        dest: options.dist.dir + '/',
        staging: options.temp.dir,

        flow: {
            steps: {
                js: ['concat', 'uglifyjs']
            },
            post: {
                js: [
                    {
                        name: 'concat',
                        createConfig: function(a,b) {
                            console.log(a,b);
                        }
                    },
                    'uglifyjs'
                ]
            }
        }
    }
}

Grunt 构建冗长(注意 createConfig 已消失):

Running "useminPrepare:useminPrepare" (useminPrepare) task
Verifying property useminPrepare.useminPrepare exists in config...OK
Files: dist/index.html
Options: dest="dist/", staging=".tmp", flow={"steps":{"js":["concat","uglifyjs"]},"post":{"js":[{"name":"concat"},"uglifyjs"]}}
Going through dist/index.html to update the config
Looking for build script HTML comment blocks

有人知道吗?

如果我用一个函数作为值指定我自己的参数,它也会被省略(如果我指定一个字符串,它不会被省略):

name: 'concat',
test: function() {
    console.log("Hello world");
},
createConfig: function() {
    console.log(a,b);
}

我发现我做错了什么,我应该在我的子任务之外指定选项,像这样:

useminPreprare: {
    options: {
        dest: options.dist.dir + '/',
        staging: options.temp.dir,

        flow: {
            steps: {
                js: ['concat', 'uglifyjs'],
                css: ['concat', 'cssmin']
            },
            post: {
                js: [
                    {
                        name: 'concat',
                        createConfig: function(a,b) {
                            console.log(a,b);
                        }
                    },
                    'uglifyjs'
                ]
            }
        }
    },
    build: {
        src: options.dist.dir + '/index.html',
    }
}

现在我可以执行 useminPrepare 任务 useminPrepare:build