我正在使用 grunt-contrib 的concat
and uglify
处理一些 javascript 的模块。目前如果src/js/
是空的,他们仍然会创建一个(空)连接文件,以及缩小版本和源映射。
我想要检测是否src/js/
继续之前文件夹为空,如果是,则任务应跳过(而不是失败)。有什么想法如何做到这一点?
该解决方案可能不是最漂亮的,但可以给您一个想法。你需要运行类似的东西npm install --save-dev glob
第一的。这是基于部分Milkshake
你提到的项目。
grunt.registerTask('build_js', function(){
// get first task's `src` config property and see
// if any file matches the glob pattern
if (grunt.config('concat').js.src.some(function(src){
return require('glob').sync(src).length;
})) {
// if so, run the task chain
grunt.task.run([
'trimtrailingspaces:js'
, 'concat:js'
, 'uglify:yomama'
]);
}
});
比较要点:https://gist.github.com/kosmotaur/61bff2bc807b28a9fcfa https://gist.github.com/kosmotaur/61bff2bc807b28a9fcfa
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)