忽略了Grunt配置功能

时间:2015-01-30 12:17:20

标签: gruntjs grunt-usemin

我正在尝试在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 build verbose(注意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);
}

1 个答案:

答案 0 :(得分:0)

我弄清楚我做错了什么,我应该在子任务之外指定选项,如下:

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:build

执行useminPrepare