当前位置:K88软件开发文章中心编程工具Grunt → 文章内容

Grunt 创建任务

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-24 10:34:09

conditionally. grunt.log.writeln('This will only log if meta.name is defined in the config.');});任务还可以访问配置属性。grunt.registerTask('foo', 'My "foo" task.', function() { // 记录属性值,如果属性未定义(undefined)则返回null。 grunt.log.writeln('The meta.name property is: ' + grunt.config('meta.name')); // 同样的记录属性值,如果属性未定义(undefined)则返回null。 grunt.log.writeln('The meta.name property is: ' + grunt.config(['meta', 'name']));});在 contrib tasks 中可以查看更多案例。CLI 参数 / 环境通过 process.env 来访问环境变量。请参考 使用命令行工具章节,查看完整的的命令行选项列表。为什么我的异步task没有完成?如果发生这种情况,可能是由于你忘记调用 this.async 方法来告诉Grunt你的任务是异步的。为了简单起见,Grunt使用同步的编码风格,可以在task体中通过调用 this.async() 将其转换为异步的。注意,传递 false 给 done() 函数就会告诉Grunt你的任务已经失败。例如:grunt.registerTask('asyncme', 'My asynchronous task.', function() { var done = this.async(); doSomethingAsync(done);});额外参考资料如果你需要更多参考资料来创建自己的 task ,请参考 API 文档

上一页  [1] [2] 


Grunt 创建任务