grunt.option的默认值

Default value for grunt.option?

本文关键字:默认值 option grunt      更新时间:2024-01-23

从cmd行,我需要能够设置一个标志,并根据该标志编译不同的文件。我相信你可以通过咕哝来实现这一点

grunt --env="dev"

但如果省略了这个标志,我希望它们成为我的grunt文件中的默认值。

grunt.option('env')

如果用户在编译时没有将env作为标志提供,我如何设置它的默认值?

创建一个包装任务,如果在调用任务时没有提供任何选项,它将把grunt.option('env')设置为默认值:

function initBuild() {
    if (!grunt.option('env')) {
        grunt.option('env', 'your-default-value-here');
    }
    grunt.task.run(taskList);
}
grunt.registerTask('build', initBuild);